Fix issue where backend was not getting created
All checks were successful
HAProxy Manager Build and Push / Build-and-Push (push) Successful in 1m39s

This commit is contained in:
jknapp 2025-03-06 21:03:08 -08:00
parent 6f395fa621
commit 7b1e8a9536

View File

@ -152,9 +152,6 @@
e.preventDefault(); e.preventDefault();
const serverItems = document.getElementById('serverList').getElementsByClassName('server-item'); const serverItems = document.getElementById('serverList').getElementsByClassName('server-item');
console.log("Form submitted");
console.log("Server items found:", serverItems.length);
const domainInput = document.getElementById('domain'); const domainInput = document.getElementById('domain');
const backendNameInput = document.getElementById('backendName'); const backendNameInput = document.getElementById('backendName');
const templateOverrideInput = document.getElementById('templateOverride'); const templateOverrideInput = document.getElementById('templateOverride');
@ -171,33 +168,18 @@
const servers = []; const servers = [];
for (const item of serverItems) { for (const item of serverItems) {
if (!item.querySelector('.form-group')) {
continue;
}
const nameInput = item.querySelector('.server-name'); const nameInput = item.querySelector('.server-name');
const addressInput = item.querySelector('.server-address'); const addressInput = item.querySelector('.server-address');
const portInput = item.querySelector('.server-port'); const portInput = item.querySelector('.server-port');
const optionsInput = item.querySelector('.server-options'); const optionsInput = item.querySelector('.server-options');
const missingFields = []; if (!nameInput || !addressInput || !portInput) {
if (!nameInput) missingFields.push('name input'); showStatus('Server configuration is incomplete', 'error');
if (!addressInput) missingFields.push('address input');
if (!portInput) missingFields.push('port input');
if (missingFields.length > 0) {
showStatus(`Server configuration is incomplete. Missing: ${missingFields.join(', ')}`, 'error');
console.error('Missing fields:', missingFields);
console.error('Server item HTML:', item.innerHTML);
return; return;
} }
const missingValues = []; if (!nameInput.value || !addressInput.value || !portInput.value) {
if (!nameInput.value) missingValues.push('server name'); showStatus('Please fill in all required server fields', 'error');
if (!addressInput.value) missingValues.push('server address');
if (!portInput.value) missingValues.push('server port');
if (missingValues.length > 0) {
showStatus(`Please fill in all required server fields: ${missingValues.join(', ')}`, 'error');
return; return;
} }
@ -205,14 +187,14 @@
name: nameInput.value, name: nameInput.value,
address: addressInput.value, address: addressInput.value,
port: parseInt(portInput.value), port: parseInt(portInput.value),
options: optionsInput ? optionsInput.value : '' options: optionsInput.value || "check"
}); });
} }
const data = { const data = {
domain: domainInput.value, domain: domainInput.value,
backend_name: backendNameInput.value, backend_name: backendNameInput.value,
template_override: templateOverrideInput ? templateOverrideInput.value : null, template_override: templateOverrideInput.value || null,
servers: servers servers: servers
}; };
@ -225,15 +207,16 @@
body: JSON.stringify(data) body: JSON.stringify(data)
}); });
const responseData = await response.json();
if (response.ok) { if (response.ok) {
showStatus('Domain added successfully!', 'success'); showStatus(`Domain added successfully! Domain ID: ${responseData.domain_id}`, 'success');
document.getElementById('domainForm').reset(); document.getElementById('domainForm').reset();
document.getElementById('serverList').innerHTML = ''; document.getElementById('serverList').innerHTML = '';
addServerField(); addServerField();
loadDomains(); loadDomains();
} else { } else {
const errorData = await response.json(); showStatus('Failed to add domain: ' + (responseData.message || 'Unknown error'), 'error');
showStatus('Failed to add domain: ' + (errorData.message || 'Unknown error'), 'error');
} }
} catch (error) { } catch (error) {
showStatus('Error: ' + error.message, 'error'); showStatus('Error: ' + error.message, 'error');
@ -309,7 +292,7 @@
fetch('/api/domains') fetch('/api/domains')
.then(response => response.json()) .then(response => response.json())
.then(domains => { .then(domains => {
const domainList = document.querySelector('.domain-list'); const domainList = document.getElementById('domainList');
domainList.innerHTML = ''; domainList.innerHTML = '';
domains.forEach(domain => { domains.forEach(domain => {
const domainDiv = document.createElement('div'); const domainDiv = document.createElement('div');
@ -319,20 +302,21 @@
<p>Backend: ${domain.backend_name}</p> <p>Backend: ${domain.backend_name}</p>
<p>SSL: ${domain.ssl_enabled ? 'Enabled' : 'Disabled'}</p> <p>SSL: ${domain.ssl_enabled ? 'Enabled' : 'Disabled'}</p>
<button onclick="requestSSL('${domain.domain}')" class="ssl-btn"> <button onclick="requestSSL('${domain.domain}')" class="ssl-btn">
${domain.ssl_enabled ? 'Disable' : 'Enable'} SSL ${domain.ssl_enabled ? 'Renew SSL' : 'Enable SSL'}
</button> </button>
<button onclick="deleteDomain('${domain.domain}')" class="delete-btn">Delete</button> <button onclick="deleteDomain('${domain.domain}')" class="delete-btn">Delete Domain</button>
`; `;
domainList.appendChild(domainDiv); domainList.appendChild(domainDiv);
}); });
}) })
.catch(error => { .catch(error => {
console.error('Error loading domains:', error); console.error('Error loading domains:', error);
showStatus('Error loading domains', 'error'); showStatus('Error loading domains: ' + error.message, 'error');
}); });
} }
addServerField(); addServerField();
loadDomains(); loadDomains();
</script> </script>
</body> </body>
</html> </html>