diff --git a/.changeset/brown-drinks-leave.md b/.changeset/brown-drinks-leave.md new file mode 100644 index 000000000..261342ab6 --- /dev/null +++ b/.changeset/brown-drinks-leave.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +public assets should always take priority over page routes in SSR deployments diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 4a15e549e..518c1fc58 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -48,6 +48,10 @@ export class App { } match(request: Request): RouteData | undefined { const url = new URL(request.url); + // ignore requests matching public assets + if (this.#manifest.assets.has(url.pathname)) { + return undefined; + } return matchRoute(url.pathname, this.#manifestData); } async render(request: Request, routeData?: RouteData): Promise { diff --git a/packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico b/packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico new file mode 100644 index 000000000..578ad458b Binary files /dev/null and b/packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico differ diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index 8c200f1c5..f2795794f 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -18,6 +18,12 @@ describe('Dynamic pages in SSR', () => { await fixture.build(); }); + async function matchRoute(path) { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('https://example.com' + path); + return app.match(request); + } + async function fetchHTML(path) { const app = await fixture.loadTestAdapterApp(); const request = new Request('http://example.com' + path); @@ -50,4 +56,9 @@ describe('Dynamic pages in SSR', () => { const json = await fetchJSON('/api/products/33'); expect(json.id).to.equal('33'); }); + + it('Public assets take priority', async () => { + const favicon = await matchRoute('/favicon.ico'); + expect(favicon).to.equal(undefined); + }); });