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:
+11
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user