-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
57 lines (51 loc) · 1.94 KB
/
index.html
File metadata and controls
57 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>udash</title>
<script type="module">
function normalizeBasePath(value) {
if (!value || value === "/") return "/";
return "/" + String(value).replace(/^\/+|\/+$/g, "") + "/";
}
function getCandidatePrefixes(pathname) {
const segments = pathname.split("/").filter(Boolean);
const prefixes = [];
for (let depth = segments.length; depth >= 0; depth -= 1) {
const prefix = ("/" + segments.slice(0, depth).join("/")).replace(/\/+$/, "");
prefixes.push(prefix || "/");
}
return [...new Set(prefixes)];
}
async function loadRuntimeConfig() {
const prefixes = getCandidatePrefixes(window.location.pathname);
for (const prefix of prefixes) {
try {
const url = (prefix === "/" ? "" : prefix) + "/config.json";
const res = await fetch(url, { cache: "no-store" });
if (!res.ok) continue;
return await res.json();
} catch (_) {
// Ignore bad candidate prefix and keep trying.
}
}
throw new Error("Unable to load runtime configuration from config.json");
}
const runtimeConfig = await loadRuntimeConfig();
const baseElement = document.createElement("base");
baseElement.href = normalizeBasePath(runtimeConfig.APP_BASE_PATH || "/");
document.head.appendChild(baseElement);
window.config = runtimeConfig;
await import("/src/main.js");
</script>
<link rel="icon" href="./favicon.ico">
</head>
<body>
<noscript>
<strong>We're sorry but udash doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
</body>
</html>