mirror of
https://github.com/myronblair/novacpx
synced 2026-06-30 17:50:41 -05:00
Fix setup-remote connection lost — EventSource can't do POST requests
proxyRunSetup() used EventSource which only sends GET. The setup-remote endpoint requires POST, so the request hit the 404 default and the SSE connection immediately errored with 'Connection lost'. Replace EventSource with fetch+ReadableStream (same pattern already used by proxySwitchLocal). Also remove the dead EventSource+close() pair that was left in proxySwitchLocal from an earlier draft. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2917,11 +2917,8 @@ window.proxySwitchLocal = () => {
|
|||||||
`, null, { cancelLabel: 'Close', showConfirm: false });
|
`, null, { cancelLabel: 'Close', showConfirm: false });
|
||||||
|
|
||||||
const log = document.getElementById('proxy-local-log');
|
const log = document.getElementById('proxy-local-log');
|
||||||
const es = new EventSource('/api/proxy/switch-local');
|
|
||||||
let done = false;
|
let done = false;
|
||||||
|
|
||||||
// POST with port — can't use native EventSource for POST, so use fetch+ReadableStream
|
|
||||||
es.close();
|
|
||||||
fetch('/api/proxy/switch-local', {
|
fetch('/api/proxy/switch-local', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
@@ -2986,27 +2983,37 @@ window.proxyRunSetup = () => {
|
|||||||
const ov = Nova.modal('Setting Up Remote Nginx Proxy', `
|
const ov = Nova.modal('Setting Up Remote Nginx Proxy', `
|
||||||
<p style="color:var(--text-muted);margin-bottom:0.75rem">Running setup on the remote proxy VM — this takes about 30 seconds.</p>
|
<p style="color:var(--text-muted);margin-bottom:0.75rem">Running setup on the remote proxy VM — this takes about 30 seconds.</p>
|
||||||
<pre id="proxy-setup-log" style="background:var(--bg-secondary);padding:0.75rem;border-radius:6px;font-size:0.78rem;max-height:320px;overflow-y:auto;white-space:pre-wrap;font-family:monospace">Connecting…\n</pre>
|
<pre id="proxy-setup-log" style="background:var(--bg-secondary);padding:0.75rem;border-radius:6px;font-size:0.78rem;max-height:320px;overflow-y:auto;white-space:pre-wrap;font-family:monospace">Connecting…\n</pre>
|
||||||
`, null, { cancelLabel: 'Close', showConfirm: false });
|
`);
|
||||||
|
|
||||||
const log = document.getElementById('proxy-setup-log');
|
const log = document.getElementById('proxy-setup-log');
|
||||||
const es = new EventSource('/api/proxy/setup-remote');
|
let done = false;
|
||||||
let done = false;
|
|
||||||
|
|
||||||
es.onmessage = (e) => {
|
fetch('/api/proxy/setup-remote', { method: 'POST', credentials: 'include' })
|
||||||
try {
|
.then(async res => {
|
||||||
const d = JSON.parse(e.data);
|
if (!res.ok) { log.textContent += '\n— Server error (' + res.status + '). Check remote host settings.\n'; return; }
|
||||||
if (d.line) { log.textContent += d.line; log.scrollTop = log.scrollHeight; }
|
const reader = res.body.getReader();
|
||||||
if (d.done) { done = true; es.close(); log.textContent += '\n— Done. Refreshing status…\n'; setTimeout(() => Nova.loadPage('nginx-proxy', window._novaPages), 1200); }
|
const dec = new TextDecoder();
|
||||||
} catch {}
|
let buf = '';
|
||||||
};
|
while (true) {
|
||||||
es.onerror = () => {
|
const { value, done: d } = await reader.read();
|
||||||
if (!done) {
|
if (d) break;
|
||||||
es.close();
|
buf += dec.decode(value, { stream: true });
|
||||||
log.textContent += '\n— Connection lost. Check remote host settings and try again.\n';
|
const parts = buf.split('\n\n');
|
||||||
}
|
buf = parts.pop();
|
||||||
};
|
for (const part of parts) {
|
||||||
// Close SSE when modal is dismissed
|
const m = part.match(/^data: (.+)$/m);
|
||||||
ov.querySelector('.modal-close')?.addEventListener('click', () => es.close());
|
if (!m) continue;
|
||||||
|
try {
|
||||||
|
const evt = JSON.parse(m[1]);
|
||||||
|
if (evt.line) { log.textContent += evt.line; log.scrollTop = log.scrollHeight; }
|
||||||
|
if (evt.done) { done = true; log.textContent += '\n— Done. Refreshing status…\n'; setTimeout(() => Nova.loadPage('nginx-proxy', window._novaPages), 1200); }
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => { log.textContent += '\n— Connection error: ' + e.message + '\n'; });
|
||||||
|
|
||||||
|
ov.querySelector('.modal-close')?.addEventListener('click', () => { done = true; });
|
||||||
};
|
};
|
||||||
|
|
||||||
window.proxyUninstall = () => {
|
window.proxyUninstall = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user