Merge pull request #27751 from kunickiaj/ajk--fix-route
Fix handling of root route when query params present
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user