From d66fa80907aef8b19ce95914ab3bd6d81bd9f34c Mon Sep 17 00:00:00 2001 From: Adam Kunicki Date: Wed, 20 Nov 2024 16:25:54 -0800 Subject: [PATCH 1/3] Fix handling of root route when query params present Signed-off-by: Adam Kunicki --- .changeset/twenty-parents-judge.md | 5 +++++ plugins/app-backend/src/service/appPlugin.test.ts | 6 +++--- plugins/app-backend/src/service/router.ts | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/twenty-parents-judge.md 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..bb5f92b536 100644 --- a/plugins/app-backend/src/service/appPlugin.test.ts +++ b/plugins/app-backend/src/service/appPlugin.test.ts @@ -93,9 +93,9 @@ describe('appPlugin', () => { ], }); - const rootContent = await fetch(`http://localhost:${server.port()}`).then( - res => res.text(), - ); + const rootContent = await fetch( + `http://localhost:${server.port()}?foo=bar`, + ).then(res => res.text()); expect(rootContent).toBe(` -`); +`; - const indexContent = await fetch( - `http://localhost:${server.port()}/index.html`, - ).then(res => res.text()); + await expect(fetch(`${baseUrl}`).then(res => res.text())).resolves.toBe( + withInjectedConfig, + ); - expect(indexContent).toBe(` - -`); + await expect( + fetch(`${baseUrl}?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}/index.html`).then(res => res.text()), + ).resolves.toBe(withInjectedConfig); - expect(htmlContent).toBe(` - -`); + await expect( + fetch(`${baseUrl}/index.html?foo=bar`).then(res => res.text()), + ).resolves.toBe(withInjectedConfig); + + await expect( + fetch(`${baseUrl}/api/app/some/html5/route`).then(res => res.text()), + ).resolves.toBe(withInjectedConfig); + + await expect( + fetch(`${baseUrl}/api/app/some/html5/route?foo=bar`).then(res => + res.text(), + ), + ).resolves.toBe(withInjectedConfig); }); }); From c666e137832f26944f3ce21eb0715532f0ee7179 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 21 Nov 2024 16:40:46 +0100 Subject: [PATCH 3/3] app-backend: use req.path for index check Signed-off-by: Patrik Oldsberg --- plugins/app-backend/src/service/router.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/app-backend/src/service/router.ts b/plugins/app-backend/src/service/router.ts index bfd0ab2516..24671fe5e9 100644 --- a/plugins/app-backend/src/service/router.ts +++ b/plugins/app-backend/src/service/router.ts @@ -306,8 +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 - const urlWithoutQuery = req.url.split('?')[0]; - if (urlWithoutQuery === '/' || urlWithoutQuery === '/index.html') { + if (req.path === '/' || req.path === '/index.html') { next('router'); } else { next();