Skip to content

Commit

Permalink
fix: exclude Vite requests from trailing slash handling (#13095)
Browse files Browse the repository at this point in the history
* fix: exclude Vite requests from trailing slash handling

* Add test

* remove extraneous config file

* Update changeset
  • Loading branch information
ascorbic authored Jan 30, 2025
1 parent f6b7839 commit 740eb60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-waves-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a bug that caused some dev server asset requests to return 404 when trailingSlash was set to "always"
3 changes: 3 additions & 0 deletions packages/astro/src/vite-plugin-astro-server/trailing-slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function trailingSlashMiddleware(settings: AstroSettings): vite.Connect.N
/* malformed uri */
return next(e);
}
if(pathname.startsWith('/_') || pathname.startsWith('/@')) {
return next();
}
if (
(trailingSlash === 'never' && pathname.endsWith('/') && pathname !== '/') ||
(trailingSlash === 'always' && !pathname.endsWith('/') && !hasFileExtension(pathname))
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/ssr-error-pages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ describe('trailing slashes for error pages', () => {
const $ = cheerio.load(html);
assert.equal($('h1').text(), `Something went horribly wrong!`);
});

it('serves Vite assets correctly when trailingSlash is always', async () => {
const response = await fixture.fetch('/@vite/client');
assert.equal(response.status, 200);
});

});

describe('Production', () => {
Expand Down

0 comments on commit 740eb60

Please sign in to comment.