Skip to content

Commit

Permalink
Updates SSR routing to always give priority to public assets (#4000)
Browse files Browse the repository at this point in the history
* matchRoute should ignore requests for public assets

* chore: add changeset
  • Loading branch information
Tony Sullivan authored Jul 20, 2022
1 parent 335e58c commit 1c1b9da
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-drinks-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

public assets should always take priority over page routes in SSR deployments
4 changes: 4 additions & 0 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions packages/astro/test/ssr-dynamic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 1c1b9da

Please sign in to comment.