diff --git a/.changeset/twenty-parents-judge.md b/.changeset/twenty-parents-judge.md new file mode 100644 index 0000000000..a639f83ba1 --- /dev/null +++ b/.changeset/twenty-parents-judge.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-app-backend': patch +--- + +Fix root route handling when query parameters are present diff --git a/plugins/app-backend/src/service/appPlugin.test.ts b/plugins/app-backend/src/service/appPlugin.test.ts index e1065e5b6a..fbb0747a64 100644 --- a/plugins/app-backend/src/service/appPlugin.test.ts +++ b/plugins/app-backend/src/service/appPlugin.test.ts @@ -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 = ` + +`; + + await expect(fetch(`${baseUrl}`).then(res => res.text())).resolves.toBe( + withInjectedConfig, ); - expect(rootContent).toBe(` - -`); + 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(` - -`); + 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(` - -`); + await expect( + fetch(`${baseUrl}/api/app/some/html5/route?foo=bar`).then(res => + res.text(), + ), + ).resolves.toBe(withInjectedConfig); }); }); diff --git a/plugins/app-backend/src/service/router.ts b/plugins/app-backend/src/service/router.ts index 1616314a62..24671fe5e9 100644 --- a/plugins/app-backend/src/service/router.ts +++ b/plugins/app-backend/src/service/router.ts @@ -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();