Fix client base path handling via explicit meta

This commit is contained in:
2026-02-05 16:42:31 +01:00
parent a6265e8656
commit f381c945a7
4 changed files with 12 additions and 9 deletions

View File

@@ -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,