app: fix auth entry point redirect

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-01-22 13:42:41 +01:00
parent 47c686e4a1
commit 3a46297ddf
+12 -1
View File
@@ -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 <div />;
}