This prevents stale localStorage geo_api_base values from forcing localhost API calls on production domains by defaulting to window.location.origin when appropriate. Made-with: Cursor
This commit is contained in:
+12
-1
@@ -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: "",
|
||||
|
||||
Reference in New Issue
Block a user