From 3a46297ddf46270c8379ad0ba336ccecfde51f9a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 22 Jan 2024 13:42:41 +0100 Subject: [PATCH] app: fix auth entry point redirect Signed-off-by: Patrik Oldsberg --- packages/app/src/auth.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/app/src/auth.tsx b/packages/app/src/auth.tsx index e06df51754..9e5f89b4c2 100644 --- a/packages/app/src/auth.tsx +++ b/packages/app/src/auth.tsx @@ -28,9 +28,20 @@ import { configApiRef, createApiFactory, discoveryApiRef, + useApi, } from '@backstage/core-plugin-api'; import { AuthProxyDiscoveryApi } from '../src/AuthProxyDiscoveryApi'; +// TODO(Rugvip): make this available via some util, or maybe Utility API? +function readBasePath(configApi: typeof configApiRef.T) { + let { pathname } = new URL( + configApi.getOptionalString('app.baseUrl') ?? '/', + 'http://sample.dev', // baseUrl can be specified as just a path + ); + pathname = pathname.replace(/\/*$/, ''); + return pathname; +} + const app = createApp({ apis: [ createApiFactory({ @@ -54,7 +65,7 @@ const app = createApp({ }); function RedirectToRoot() { - window.location.pathname += '/..'; + window.location.pathname = readBasePath(useApi(configApiRef)); return
; }