Fix client base path handling via explicit meta
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
const defaultHeaders = { "Content-Type": "application/json" };
|
||||
|
||||
const metaBase = document.querySelector('meta[name="app-base"]')?.content || "";
|
||||
const autoBase = (() => {
|
||||
const parts = window.location.pathname.split("/").filter(Boolean);
|
||||
return parts.length ? `/${parts[0]}` : "";
|
||||
})();
|
||||
const basePath = metaBase || autoBase;
|
||||
const rawBase = document.querySelector('meta[name="app-base"]')?.content || "";
|
||||
const basePath = normalizeBase(rawBase);
|
||||
const withBase = (path) => `${basePath}${path}`;
|
||||
|
||||
function normalizeBase(value) {
|
||||
if (!value) return "";
|
||||
if (!value.startsWith("/")) return `/${value}`;
|
||||
return value.endsWith("/") ? value.slice(0, -1) : value;
|
||||
}
|
||||
|
||||
async function request(path, { method = "GET", body } = {}) {
|
||||
const res = await fetch(withBase(path), {
|
||||
method,
|
||||
|
||||
Reference in New Issue
Block a user