From f7b23d5cf19e85181176856b46c88ae7b3d78462 Mon Sep 17 00:00:00 2001 From: Drew Powers <1369770+drwpow@users.noreply.github.com> Date: Fri, 19 Nov 2021 12:57:24 -0700 Subject: [PATCH] Allow search params (#1927) Fixes #1795 --- packages/astro/src/core/dev/index.ts | 4 ++-- packages/astro/test/dev-routing.test.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/core/dev/index.ts b/packages/astro/src/core/dev/index.ts index 3aad5e444..924cd87ec 100644 --- a/packages/astro/src/core/dev/index.ts +++ b/packages/astro/src/core/dev/index.ts @@ -110,7 +110,7 @@ export class AstroDevServer { } const route = this.mostRecentRoute; - const pathname = route?.pathname ?? '/'; + const [pathname, search = undefined] = (route?.pathname ?? '/').split('?'); if (!route) { viteServer.ws.send({ @@ -274,7 +274,7 @@ export class AstroDevServer { private async handleRequest(req: http.IncomingMessage, res: http.ServerResponse, next: NextFunction) { if (!this.viteServer) throw new Error(`AstroDevServer.start() not called`); - let pathname = req.url || '/'; // original request + let [pathname, search = undefined] = (req.url || '/').split('?'); // original request const reqStart = performance.now(); let filePath: URL | undefined; try { diff --git a/packages/astro/test/dev-routing.test.js b/packages/astro/test/dev-routing.test.js index 98ea79df3..129942c83 100644 --- a/packages/astro/test/dev-routing.test.js +++ b/packages/astro/test/dev-routing.test.js @@ -23,6 +23,11 @@ describe('Development Routing', () => { expect(response.status).to.equal(200); }); + it('200 when adding search params', async () => { + const response = await fixture.fetch('/?foo=bar'); + expect(response.status).to.equal(200); + }); + it('200 when loading non-root page', async () => { const response = await fixture.fetch('/another'); expect(response.status).to.equal(200);