core-app-api: fix base url rewriting

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-12-07 14:51:34 +01:00
parent d0b634170e
commit 6870b43dd1
3 changed files with 22 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/core-app-api': patch
---
Fix for the automatic rewriting of base URLs.
@@ -624,21 +624,18 @@ describe('Integration Test', () => {
describe('relative url resolvers', () => {
it.each([
[
[document.location.href, document.location.href],
['http://localhost', 'http://localhost'],
{
backend: {
baseUrl: 'http://localhost:8008/',
baseUrl: 'http://localhost:8008',
},
app: {
baseUrl: 'http://localhost:8008/',
baseUrl: 'http://localhost:8008',
},
},
],
[
[
`${document.location.origin}/backstage`,
`${document.location.origin}/backstage`,
],
['http://localhost/backstage', 'http://localhost/backstage'],
{
backend: {
baseUrl: 'http://test.com/backstage',
@@ -650,8 +647,8 @@ describe('Integration Test', () => {
],
[
[
`${document.location.origin}/backstage/instance`,
`${document.location.origin}/backstage/instance`,
'http://localhost/backstage/instance',
'http://localhost/backstage/instance',
],
{
backend: {
@@ -664,8 +661,8 @@ describe('Integration Test', () => {
],
[
[
`${document.location.origin}/backstage/instance`,
`http://test.com/backstage/instance`,
'http://localhost/backstage/instance',
'http://test.com/backstage/instance',
],
{
backend: {
+9 -7
View File
@@ -179,7 +179,7 @@ function useConfigLoader(
return new URL(
fullUrl.replace(getOrigin(fullUrl), ''),
document.location.origin,
).href;
).href.replace(/\/$/, '');
};
/**
@@ -199,15 +199,17 @@ function useConfigLoader(
const backendOrigin = getOrigin(backendBaseUrl);
if (appOrigin === backendOrigin) {
relativeResolverConfig.data.backend = {
baseUrl: overrideOrigin(backendBaseUrl),
};
const newBackendBaseUrl = overrideOrigin(backendBaseUrl);
if (backendBaseUrl !== newBackendBaseUrl) {
relativeResolverConfig.data.backend = { baseUrl: newBackendBaseUrl };
}
}
}
if (appBaseUrl) {
relativeResolverConfig.data.app = {
baseUrl: overrideOrigin(appBaseUrl),
};
const newAppBaseUrl = overrideOrigin(appBaseUrl);
if (appBaseUrl !== newAppBaseUrl) {
relativeResolverConfig.data.app = { baseUrl: newAppBaseUrl };
}
}
/**
* Only add the relative config if there is actually data to add.