diff options
author | 2022-07-20 20:54:46 +0000 | |
---|---|---|
committer | 2022-07-20 20:54:46 +0000 | |
commit | 1c1b9da624ec811e3e4a34b63f07bce61d2dcd04 (patch) | |
tree | 9ac5d1ca22ebf68199dc6835452155f98a5def13 | |
parent | 335e58cd8b76a40e50430c152cd6244022494189 (diff) | |
download | astro-1c1b9da624ec811e3e4a34b63f07bce61d2dcd04.tar.gz astro-1c1b9da624ec811e3e4a34b63f07bce61d2dcd04.tar.zst astro-1c1b9da624ec811e3e4a34b63f07bce61d2dcd04.zip |
Updates SSR routing to always give priority to public assets (#4000)
* matchRoute should ignore requests for public assets
* chore: add changeset
-rw-r--r-- | .changeset/brown-drinks-leave.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/app/index.ts | 4 | ||||
-rw-r--r-- | packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico | bin | 0 -> 4286 bytes | |||
-rw-r--r-- | packages/astro/test/ssr-dynamic.test.js | 11 |
4 files changed, 20 insertions, 0 deletions
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<Response> { diff --git a/packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico b/packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico Binary files differnew file mode 100644 index 000000000..578ad458b --- /dev/null +++ b/packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico 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); + }); }); |