Skip to content

Commit 740eb60

Browse files
authored
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
1 parent f6b7839 commit 740eb60

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

.changeset/large-waves-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes a bug that caused some dev server asset requests to return 404 when trailingSlash was set to "always"

packages/astro/src/vite-plugin-astro-server/trailing-slash.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export function trailingSlashMiddleware(settings: AstroSettings): vite.Connect.N
2222
/* malformed uri */
2323
return next(e);
2424
}
25+
if(pathname.startsWith('/_') || pathname.startsWith('/@')) {
26+
return next();
27+
}
2528
if (
2629
(trailingSlash === 'never' && pathname.endsWith('/') && pathname !== '/') ||
2730
(trailingSlash === 'always' && !pathname.endsWith('/') && !hasFileExtension(pathname))

packages/astro/test/ssr-error-pages.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ describe('trailing slashes for error pages', () => {
169169
const $ = cheerio.load(html);
170170
assert.equal($('h1').text(), `Something went horribly wrong!`);
171171
});
172+
173+
it('serves Vite assets correctly when trailingSlash is always', async () => {
174+
const response = await fixture.fetch('/@vite/client');
175+
assert.equal(response.status, 200);
176+
});
177+
172178
});
173179

174180
describe('Production', () => {

0 commit comments

Comments
 (0)