From 1c1b9da624ec811e3e4a34b63f07bce61d2dcd04 Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Wed, 20 Jul 2022 20:54:46 +0000 Subject: [PATCH] Updates SSR routing to always give priority to public assets (#4000) * matchRoute should ignore requests for public assets * chore: add changeset --- .changeset/brown-drinks-leave.md | 5 +++++ packages/astro/src/core/app/index.ts | 4 ++++ .../test/fixtures/ssr-dynamic/public/favicon.ico | Bin 0 -> 4286 bytes packages/astro/test/ssr-dynamic.test.js | 11 +++++++++++ 4 files changed, 20 insertions(+) create mode 100644 .changeset/brown-drinks-leave.md create mode 100644 packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico diff --git a/.changeset/brown-drinks-leave.md b/.changeset/brown-drinks-leave.md new file mode 100644 index 000000000000..261342ab6e50 --- /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 4a15e549e716..518c1fc582f8 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 0000000000000000000000000000000000000000..578ad458b8906c08fbed84f42b045fea04db89d1 GIT binary patch literal 4286 zcmchZF=!M)6ox0}Fc8GdTHG!cdIY>nA!3n2f|wxIl0rn}Hl#=uf>?-!2r&jMEF^_k zh**lGut*gwBmoNv7AaB&2~nbzULg{WBhPQ{ZVzvF_HL8Cb&hv$_s#qN|IO^o>?+mA zuTW6tU%k~z<&{z+7$G%*nRsTcEO|90xy<-G5&JTt%CgZZCDT4%R?+{Vd^wh>P8_)} z`+dF$HQb9!>1o`Ivn;GInlCw{9T@Rt%q+d^T3Ke%cxkk;$v`{s^zCB9nHAv6w$Vbn z8fb<+eQTNM`;rf9#obfGnV#3+OQEUv4gU;{oA@zol%keY9-e>4W>p7AHmH~&!P7f7!Uj` zwgFeQ=<3G4O;mwWO`L!=R-=y3_~-DPjH3W^3f&jjCfC$o#|oGaahSL`_=f?$&Aa+W z2h8oZ+@?NUcjGW|aWJfbM*ZzxzmCPY`b~RobNrrj=rd`=)8-j`iSW64@0_b6?;GYk zNB+-fzOxlqZ?`y{OA$WigtZXa8)#p#=DPYxH=VeC_Q5q9Cv`mvW6*zU&Gnp1;oPM6 zaK_B3j(l^FyJgYeE9RrmDyhE7W2}}nW%ic#0v@i1E!yTey$W)U>fyd+!@2hWQ!Wa==NAtKoj`f3tp4y$Al`e;?)76?AjdaRR>|?&r)~3Git> zb1)a?uiv|R0_{m#A9c;7)eZ1y6l@yQ#oE*>(Z2fG-&&smPa2QTW>m*^K65^~`coP$ z8y5Y?iS<4Gz{Zg##$1mk)u-0;X|!xu^FCr;ce~X<&UWE&pBgqfYmEJTzpK9I%vr%b z3Ksd6qlPJLI%HFfeXK_^|BXiKZC>Ocu(Kk6hD3G-8usLzVG^q00Qh gz)s7ge@$ApxGu7=(6IGIk+uG&HTev01^#CH3$(Wk5&!@I literal 0 HcmV?d00001 diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index 8c200f1c5873..f2795794f5c1 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); + }); });