Add configurable BasePath for subfolder hosting and update frontend base handling

This commit is contained in:
2026-01-28 20:00:54 +01:00
parent 1129947183
commit 4509c0f8a8
5 changed files with 21 additions and 3 deletions

View File

@@ -5,6 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CoopGameChooser</title>
<link rel="stylesheet" href="styles.css">
<!-- Optional: set data-app-base if served from a subfolder (e.g., /vote) -->
<meta name="app-base" content="">
</head>
<body>
<div class="status-bar">

View File

@@ -1,7 +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 withBase = (path) => `${basePath}${path}`;
async function request(path, { method = "GET", body, adminKey } = {}) {
const res = await fetch(path, {
const res = await fetch(withBase(path), {
method,
headers: {
...defaultHeaders,