Merge pull request #27751 from kunickiaj/ajk--fix-route

Fix handling of root route when query params present
This commit is contained in:
Patrik Oldsberg
2024-11-21 22:00:03 +01:00
committed by GitHub
3 changed files with 32 additions and 24 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-app-backend': patch
---
Fix root route handling when query parameters are present
@@ -93,34 +93,37 @@ describe('appPlugin', () => {
],
});
const rootContent = await fetch(`http://localhost:${server.port()}`).then(
res => res.text(),
const baseUrl = `http://localhost:${server.port()}`;
const withInjectedConfig = `<html><head>
<script type="backstage.io/config">
[]
</script>
</head></html>`;
await expect(fetch(`${baseUrl}`).then(res => res.text())).resolves.toBe(
withInjectedConfig,
);
expect(rootContent).toBe(`<html><head>
<script type="backstage.io/config">
[]
</script>
</head></html>`);
await expect(
fetch(`${baseUrl}?foo=bar`).then(res => res.text()),
).resolves.toBe(withInjectedConfig);
const indexContent = await fetch(
`http://localhost:${server.port()}/index.html`,
).then(res => res.text());
await expect(
fetch(`${baseUrl}/index.html`).then(res => res.text()),
).resolves.toBe(withInjectedConfig);
expect(indexContent).toBe(`<html><head>
<script type="backstage.io/config">
[]
</script>
</head></html>`);
await expect(
fetch(`${baseUrl}/index.html?foo=bar`).then(res => res.text()),
).resolves.toBe(withInjectedConfig);
const htmlContent = await fetch(
`http://localhost:${server.port()}/api/app/some/html5/route`,
).then(res => res.text());
await expect(
fetch(`${baseUrl}/api/app/some/html5/route`).then(res => res.text()),
).resolves.toBe(withInjectedConfig);
expect(htmlContent).toBe(`<html><head>
<script type="backstage.io/config">
[]
</script>
</head></html>`);
await expect(
fetch(`${baseUrl}/api/app/some/html5/route?foo=bar`).then(res =>
res.text(),
),
).resolves.toBe(withInjectedConfig);
});
});
+1 -1
View File
@@ -306,7 +306,7 @@ async function createEntryPointRouter({
const rootRouter = Router();
rootRouter.use((req, _res, next) => {
// Make sure / and /index.html are handled by the HTML5 route below
if (req.url === '/' || req.url === '/index.html') {
if (req.path === '/' || req.path === '/index.html') {
next('router');
} else {
next();