Probe: require JSON version field to confirm same-origin API

SPA-fallback static hosts return 200 HTML for /api/version, which falsely
triggered same-origin mode. Now validate the body parses as JSON with a string
version field before switching to a relative base.
This commit is contained in:
2026-08-15 14:33:00 +03:00
parent 966ada21eb
commit 62ba09d25e
+7 -6
View File
@@ -2644,13 +2644,14 @@ let pysimBase = 'http://127.0.0.1:8080';
async function pysimDetectSameOrigin() {
try {
const res = await fetch('/api/version', { method: 'GET', cache: 'no-store' });
if (res.ok) {
pysimBase = '';
const urlEl = document.getElementById('pysim-url');
if (urlEl) { urlEl.value = ''; urlEl.placeholder = '(same origin)'; }
}
if (!res.ok) return;
const data = await res.json();
if (!data || typeof data.version !== 'string') return;
pysimBase = '';
const urlEl = document.getElementById('pysim-url');
if (urlEl) { urlEl.value = ''; urlEl.placeholder = '(same origin)'; }
} catch (e) {
// no co-located API (file://, plain static server) — keep the default
// no co-located API (file://, plain static server, SPA fallback) — keep default
}
}
pysimDetectSameOrigin();