0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Updates SSR routing to always give priority to public assets (#4000)

* matchRoute should ignore requests for public assets

* chore: add changeset
This commit is contained in:
Tony Sullivan 2022-07-20 20:54:46 +00:00 committed by GitHub
parent 335e58cd8b
commit 1c1b9da624
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
public assets should always take priority over page routes in SSR deployments

View file

@ -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> {

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

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