0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

fix: exclude Vite requests from trailing slash handling (#13095)

* fix: exclude Vite requests from trailing slash handling

* Add test

* remove extraneous config file

* Update changeset
This commit is contained in:
Matt Kane 2025-01-30 16:04:07 +00:00 committed by GitHub
parent f6b7839411
commit 740eb6019f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 0 deletions

View file

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

View file

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

View file

@ -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', () => {