diff --git a/web/app.js b/web/app.js index 5a53217..b862074 100644 --- a/web/app.js +++ b/web/app.js @@ -4,9 +4,20 @@ import { scanQRFromCamera } from "./scanner.js"; const { createApp, ref, reactive, onMounted, watch } = Vue; +function normalizeInitialApiBase() { + const saved = localStorage.getItem("geo_api_base") || ""; + const host = window.location.hostname.toLowerCase(); + if (saved) { + const pointsToLocalhost = /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?(\/|$)/i.test(saved); + const runningHosted = host !== "localhost" && host !== "127.0.0.1"; + if (!(runningHosted && pointsToLocalhost)) return saved; + } + return window.location.origin; +} + createApp({ setup() { - const apiBase = ref(localStorage.getItem("geo_api_base") || "https://tenerife.baby"); + const apiBase = ref(normalizeInitialApiBase()); const state = reactive({ publicKey: "", privateKey: "", diff --git a/web/leaflet-demo.js b/web/leaflet-demo.js index 18f034d..2399700 100644 --- a/web/leaflet-demo.js +++ b/web/leaflet-demo.js @@ -51,6 +51,12 @@ function currentApiBase() { return apiBaseEl.value.trim().replace(/\/+$/g, ""); } +function shouldUseHostedDefault(savedBase) { + const host = window.location.hostname.toLowerCase(); + if (host === "localhost" || host === "127.0.0.1") return false; + return /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?(\/|$)/i.test(savedBase || ""); +} + function extFromFilename(name) { const idx = name.lastIndexOf("."); if (idx <= 0) return ""; @@ -331,9 +337,13 @@ document.getElementById("uploadAsset").onclick = async () => { }; const savedBase = localStorage.getItem("geo_api_base"); -if (savedBase) { +if (savedBase && !shouldUseHostedDefault(savedBase)) { apiBaseEl.value = savedBase; setClientBase(savedBase); +} else { + const defaultBase = window.location.origin; + apiBaseEl.value = defaultBase; + setClientBase(defaultBase); } renderSharedAssetFromQuery(); diff --git a/web/maplibre-demo.js b/web/maplibre-demo.js index d47a780..da84e45 100644 --- a/web/maplibre-demo.js +++ b/web/maplibre-demo.js @@ -51,6 +51,12 @@ function currentApiBase() { return apiBaseEl.value.trim().replace(/\/+$/g, ""); } +function shouldUseHostedDefault(savedBase) { + const host = window.location.hostname.toLowerCase(); + if (host === "localhost" || host === "127.0.0.1") return false; + return /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?(\/|$)/i.test(savedBase || ""); +} + function extFromFilename(name) { const idx = name.lastIndexOf("."); if (idx <= 0) return ""; @@ -644,7 +650,7 @@ map.on("click", (event) => { }); const savedBase = localStorage.getItem("geo_api_base"); -if (savedBase) { +if (savedBase && !shouldUseHostedDefault(savedBase)) { apiBaseEl.value = savedBase; setClientBase(savedBase); } else {