mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-01-31 01:39:08 +01:00
Load configurations in parallel & stop suppressing errors
correct commit this time
This commit is contained in:
parent
50bb5b2e99
commit
f830d10c68
1 changed files with 13 additions and 18 deletions
|
@ -4,26 +4,21 @@ import { ClientConfig } from '../hooks/useClientConfig';
|
||||||
import { trimTrailingSlash } from '../utils/common';
|
import { trimTrailingSlash } from '../utils/common';
|
||||||
|
|
||||||
const getClientConfig = async (): Promise<ClientConfig> => {
|
const getClientConfig = async (): Promise<ClientConfig> => {
|
||||||
let url = `${trimTrailingSlash(import.meta.env.BASE_URL)}/config.${window.location.hostname}.json`;
|
const defaultConfig = fetch(
|
||||||
let config = await fetch(url, { method: 'GET' });
|
`${trimTrailingSlash(import.meta.env.BASE_URL)}/config.json`, { method: 'GET' }
|
||||||
|
);
|
||||||
|
const perSiteConfig = fetch(
|
||||||
|
`${trimTrailingSlash(import.meta.env.BASE_URL)}/config.${window.location.hostname}.json`, { method: "GET" }
|
||||||
|
);
|
||||||
|
|
||||||
let loadedConfig = null;
|
return perSiteConfig.then(
|
||||||
try {
|
async (pscResponse) => {
|
||||||
if(config.ok && import.meta.env.MODE != "development") {
|
if (import.meta.env.MODE === "development" || !pscResponse.ok) {
|
||||||
loadedConfig = await config.json();
|
return defaultConfig.then((dcResponse) => dcResponse.json());
|
||||||
|
}
|
||||||
|
return pscResponse.json();
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
)
|
||||||
|
|
||||||
if(!loadedConfig) {
|
|
||||||
url = `${trimTrailingSlash(import.meta.env.BASE_URL)}/config.json`;
|
|
||||||
config = await fetch(url, { method: 'GET' });
|
|
||||||
try {
|
|
||||||
loadedConfig = await config.json();
|
|
||||||
} catch (e) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return loadedConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type ClientConfigLoaderProps = {
|
type ClientConfigLoaderProps = {
|
||||||
|
|
Loading…
Reference in a new issue