Respect base url when loading config.json (#274)

* Respect base url when loading config.json

* update readme
This commit is contained in:
Aine
2025-01-09 22:36:45 +02:00
committed by GitHub
parent e66c321ef9
commit ddf3298b41
5 changed files with 34 additions and 3 deletions

View File

@@ -22,10 +22,16 @@ let config: Config = {
};
export const FetchConfig = async () => {
// load config.json and honor vite base url (import.meta.env.BASE_URL)
// if that url doesn't have a trailing slash - add it
let configJSONUrl = "config.json"
if (import.meta.env.BASE_URL) {
configJSONUrl = `${import.meta.env.BASE_URL.replace(/\/?$/, '/')}config.json`;
}
try {
const resp = await fetch("config.json");
const resp = await fetch(configJSONUrl);
const configJSON = await resp.json();
console.log("Loaded config.json", configJSON);
console.log("Loaded", configJSONUrl, configJSON);
LoadConfig(configJSON);
} catch (e) {
console.error(e);