From 7b74489a54089b4e0f4f35b6e40a2ac8dbcce3a1 Mon Sep 17 00:00:00 2001 From: Tony Balascio Date: Mon, 10 Aug 2026 02:35:16 +0000 Subject: [PATCH] Add/Update web/assets/js/main.js (Batch 4: real audit API backend + fetch wiring; port 8199 to avoid Gitea 3000 collision) --- web/assets/js/main.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) 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