Skip to content

Commit 6fcceeb

Browse files
authored
fix: make htmlFallback more permissive (#15059)
1 parent 81fde80 commit 6fcceeb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/vite/src/node/server/middlewares/htmlFallback.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ export function htmlFallbackMiddleware(
1414
if (
1515
// Only accept GET or HEAD
1616
(req.method !== 'GET' && req.method !== 'HEAD') ||
17-
// Ignore JSON requests
18-
req.headers.accept?.includes('application/json') ||
1917
// Require Accept: text/html or */*
2018
!(
2119
req.headers.accept === undefined || // equivalent to `Accept: */*`
20+
req.headers.accept === '' || // equivalent to `Accept: */*`
2221
req.headers.accept.includes('text/html') ||
2322
req.headers.accept.includes('*/*')
2423
)

playground/html/__tests__/html.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,19 @@ test('html serve behavior', async () => {
414414
expect(bothSlashIndexHtml.status).toBe(200)
415415
expect(await bothSlashIndexHtml.text()).toContain('both/index.html')
416416
})
417+
418+
test('html fallback works non browser accept header', async () => {
419+
expect((await fetch(viteTestUrl, { headers: { Accept: '' } })).status).toBe(
420+
200,
421+
)
422+
// defaults to "Accept: */*"
423+
expect((await fetch(viteTestUrl)).status).toBe(200)
424+
// wait-on uses axios and axios sends this accept header
425+
expect(
426+
(
427+
await fetch(viteTestUrl, {
428+
headers: { Accept: 'application/json, text/plain, */*' },
429+
})
430+
).status,
431+
).toBe(200)
432+
})

0 commit comments

Comments
 (0)