api: Update prod baseURL to be absolute

Only an absolute baseURL will work with our new Reqer class.
This commit is contained in:
IRHM
2026-07-29 18:43:38 +01:00
committed by momi
parent 1f4b917661
commit 3967a3f13f
+29 -6
View File
@@ -18,14 +18,37 @@ import {
import { Reqer, ReqerError } from "./fetch";
import { notify, unNotify } from "./notify";
import { browser } from "$app/environment";
import { page } from "$app/state";
const { MODE } = import.meta.env;
export const baseURL =
MODE === "development"
? browser
? `${location.protocol}//${location.hostname}:3080/api`
: "http://127.0.0.1:3080/api"
: "/api";
export const baseURL: string = ((): string => {
try {
// NOTE: Only the values returned under the if (browser) statements matter,
// since we only use this variable from the browser, I've left in the
// untested fallbacks anyways.
if (MODE === "development") {
if (browser) {
return `${location.protocol}//${location.hostname}:3080/api`;
}
return "http://127.0.0.1:3080/api";
}
// prod
if (browser) {
return `${location.origin}/api`;
}
return `${page.url.origin}/api`;
} catch (err) {
console.error("api: baseURL construction failed!", err);
if (browser) {
notify({
type: "error",
text: "Failed to create your API baseURL. Please look in console for more details.",
});
}
// This return value won't work, but just returning something anyways.
return "/api";
}
})();
console.log("api: baseURL constructed:", baseURL);
export const req = new Reqer(baseURL, true);