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);