fix: Start if BASE_URL is not defined (#677)

This commit is contained in:
Dirk Klimpel 2025-05-30 09:01:22 +02:00 committed by GitHub
parent 7a286ad506
commit ef8ae9b38f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,13 @@ import { createRoot } from "react-dom/client";
import App from "./App";
import { AppContext } from "./AppContext";
fetch(`${import.meta.env.BASE_URL}/config.json`)
const baseUrl = import.meta.env.BASE_URL;
const configJSON = "config.json";
// if import.meta.env.BASE_URL have a trailing slash, remove it
// load config.json from relative path if import.meta.env.BASE_URL is None or empty
const configJSONUrl = baseUrl ? `${baseUrl.replace(/\/$/, "")}/${configJSON}` : configJSON;
fetch(configJSONUrl)
.then(res => res.json())
.then(props =>
createRoot(document.getElementById("root")).render(