core-app-api: fix base url rewriting
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user