diff --git a/web/assets/js/main.js b/web/assets/js/main.js
index 7d5b361..319ab9e 100644
--- a/web/assets/js/main.js
+++ b/web/assets/js/main.js
@@ -35,7 +35,7 @@ document.addEventListener('DOMContentLoaded', () => {
rejectBtn.classList.add('opacity-50', 'cursor-not-allowed');
}
- // --- COLD AUDIT FORM LOGIC ---
+ // --- COLD AUDIT FORM LOGIC (REAL BACKEND) ---
const auditForm = document.getElementById('audit-form');
if (auditForm) {
auditForm.addEventListener('submit', async (e) => {
@@ -46,18 +46,42 @@ document.addEventListener('DOMContentLoaded', () => {
submitBtn.disabled = true;
submitBtn.textContent = 'Transmitting...';
submitBtn.classList.add('opacity-75', 'cursor-not-allowed');
+ formStatus.classList.add('hidden');
- // Mocking the POST to Formspree / VPS Endpoint (74.208.111.99)
- // In production, replace this setTimeout with a real fetch() POST
- setTimeout(() => {
- formStatus.className = 'mt-4 p-4 rounded border text-sm border-green-300 bg-green-50 text-green-800';
- formStatus.innerHTML = 'Protocol Initiated: Your Layer 1a Cold Audit request has been received. A human analyst will review your entity footprint within 24 hours.';
+ const formData = new FormData(auditForm);
+ const payload = Object.fromEntries(formData.entries());
+
+ // API endpoint. Default: same-origin /api/audit (routed to the
+ // Node backend by Caddy on the VPS) — avoids mixed-content/CORS.
+ // Direct IP alt (local test / no proxy): http://74.208.111.99:8199/api/audit
+ const API_URL = (typeof window.DOP_API_URL !== 'undefined')
+ ? window.DOP_API_URL
+ : '/api/audit';
+
+ try {
+ const response = await fetch(API_URL, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(payload)
+ });
+ const result = await response.json();
+
+ if (response.ok) {
+ formStatus.className = 'mt-4 p-4 rounded border text-sm border-green-300 bg-green-50 text-green-800';
+ formStatus.innerHTML = 'Protocol Initiated: Your Layer 1a Cold Audit request has been received. A human analyst will review your entity footprint within 24 hours.';
+ auditForm.reset();
+ } else {
+ throw new Error(result.message || 'Transmission failed');
+ }
+ } catch (error) {
+ formStatus.className = 'mt-4 p-4 rounded border text-sm border-red-300 bg-red-50 text-red-800';
+ formStatus.innerHTML = `Transmission Error: ${error.message}. Please try again or contact us directly.`;
+ } finally {
formStatus.classList.remove('hidden');
- auditForm.reset();
submitBtn.textContent = 'Initiate Audit';
submitBtn.disabled = false;
submitBtn.classList.remove('opacity-75', 'cursor-not-allowed');
- }, 1500);
+ }
});
}
});
\ No newline at end of file