From 2c03d56eb9584b6de8e585c5b4a32d5131dc8519 Mon Sep 17 00:00:00 2001 From: Frank Jogeleit Date: Tue, 9 Apr 2024 18:46:43 +0200 Subject: [PATCH] fix api baseURL for subpath Signed-off-by: Frank Jogeleit --- frontend/modules/core/plugins/apis.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/modules/core/plugins/apis.ts b/frontend/modules/core/plugins/apis.ts index fc2ea2d..f6fc92e 100644 --- a/frontend/modules/core/plugins/apis.ts +++ b/frontend/modules/core/plugins/apis.ts @@ -3,9 +3,11 @@ import {cluster, create} from '~/modules/core/api' import {useConfigStore} from "~/store/config"; import {type Config, DisplayMode} from "~/modules/core/types"; +const trimSlashes = (str: string) => str.split('/').filter(p => !!p).join('/') + export default defineNuxtPlugin(async () => { const config = useRuntimeConfig() - const api = create({ baseURL: config.public.coreApi as string, prefix: cluster.value }) + const api = create({ baseURL: config.public.coreApi || `//${window.location.host}/${trimSlashes(window.location.pathname)}`, prefix: cluster.value }) const apiConfig = await api.config().catch((error): Config => { console.error(`failed to load config: ${error}`)