Skip to content

Commit

Permalink
fix(server): skipped for ended response (#5230)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 9, 2021
1 parent a3f2238 commit 7255fd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export function indexHtmlMiddleware(
): Connect.NextHandleFunction {
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
return async function viteIndexHtmlMiddleware(req, res, next) {
if (res.writableEnded) {
return next()
}

const url = req.url && cleanUrl(req.url)
// spa-fallback always redirects to /index.html
if (url?.endsWith('.html') && req.headers['sec-fetch-dest'] !== 'script') {
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/server/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function send(
cacheControl = 'no-cache',
map?: SourceMap | null
): void {
if (res.writableEnded) {
return
}

if (req.headers['if-none-match'] === etag) {
res.statusCode = 304
return res.end()
Expand Down

0 comments on commit 7255fd5

Please sign in to comment.