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:
parent
335e58cd8b
commit
1c1b9da624
4 changed files with 20 additions and 0 deletions
5
.changeset/brown-drinks-leave.md
Normal file
5
.changeset/brown-drinks-leave.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
public assets should always take priority over page routes in SSR deployments
|
|
@ -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> {
|
||||
|
|
BIN
packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico
vendored
Normal file
BIN
packages/astro/test/fixtures/ssr-dynamic/public/favicon.ico
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue