handle relative urls when self-hosting

This commit is contained in:
Paul Miller
2023-09-27 16:01:59 -05:00
committed by Tony Giorgio
parent 368cf43350
commit 9caa91242a

View File

@@ -14,6 +14,7 @@ export type MutinyWalletSettingStrings = {
subscriptions?: string;
storage?: string;
scorer?: string;
selfhosted?: string;
};
const SETTINGS_KEYS = [
@@ -61,6 +62,11 @@ const SETTINGS_KEYS = [
name: "scorer",
storageKey: "USER_SETTINGS_scorer",
default: import.meta.env.VITE_SCORER
},
{
name: "selfhosted",
storageKey: "USER_SETTINGS_selfhosted",
default: import.meta.env.VITE_SELFHOSTED
}
];
@@ -99,6 +105,23 @@ export async function getSettings() {
settings[n] = item as string;
});
// VITE_PROXY and VITE_STORAGE might be set as relative URLs when self-hosting, so we need to make them absolute
const selfhosted = settings.selfhosted === "true";
// Expect urls like /_services/proxy and /_services/storage
if (selfhosted) {
const base = window.location.origin;
console.log("Self-hosted mode enabled, using base URL", base);
const proxy = settings.proxy;
const storage = settings.storage;
if (proxy && proxy.startsWith("/")) {
settings.proxy = base + proxy;
}
if (storage && storage.startsWith("/")) {
settings.storage = base + storage;
}
}
if (!settings.network || !settings.proxy || !settings.esplora) {
throw new Error(
"Missing a default setting for network, proxy, or esplora. Check your .env file to make sure it looks like .env.sample"