Skip to content

Commit

Permalink
fix(preview): allow path containing . to fallback to index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored and patak-dev committed Sep 29, 2023
1 parent dae6d0a commit fddc151
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export async function preview(
etag: true,
dev: true,
single: config.appType === 'spa',
ignores: false,
setHeaders(res) {
if (headers) {
for (const name in headers) {
Expand Down
10 changes: 7 additions & 3 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ test('should get a 404 when using incorrect case', async () => {
'image/png',
)
// fallback to index.html
expect((await fetchPath('ICON.png')).headers.get('Content-Type')).toBe(
isBuild ? 'text/html; charset=utf-8' : 'text/html',
const iconPngResult = await fetchPath('ICON.png')
expect(iconPngResult.headers.get('Content-Type')).toBe(
isBuild ? 'text/html;charset=utf-8' : 'text/html',
)
expect(iconPngResult.status).toBe(200)

expect((await fetchPath('bar')).headers.get('Content-Type')).toBe('')
// fallback to index.html
expect((await fetchPath('BAR')).headers.get('Content-Type')).toContain(
const barResult = await fetchPath('BAR')
expect(barResult.headers.get('Content-Type')).toContain(
isBuild ? 'text/html;charset=utf-8' : 'text/html',
)
expect(barResult.status).toBe(200)
})

test('should fallback to index.html when accessing non-existant html file', async () => {
Expand Down
10 changes: 5 additions & 5 deletions playground/legacy/__tests__/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ test('generates assets', async () => {
() => page.textContent('#assets'),
isBuild
? [
'index: text/html; charset=utf-8',
'index-legacy: text/html; charset=utf-8',
'chunk-async: text/html; charset=utf-8',
'chunk-async-legacy: text/html; charset=utf-8',
'index: text/html;charset=utf-8',
'index-legacy: text/html;charset=utf-8',
'chunk-async: text/html;charset=utf-8',
'chunk-async-legacy: text/html;charset=utf-8',
'immutable-chunk: application/javascript',
'immutable-chunk-legacy: application/javascript',
'polyfills-legacy: text/html; charset=utf-8',
'polyfills-legacy: text/html;charset=utf-8',
].join('\n')
: [
'index: text/html',
Expand Down

0 comments on commit fddc151

Please sign in to comment.