From ef8ae9b38fbd7c39c5c1274a00fe4826789de140 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Fri, 30 May 2025 09:01:22 +0200 Subject: [PATCH] fix: Start if `BASE_URL` is not defined (#677) --- src/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index 156cc5d..157457b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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(