Skip to content

Commit

Permalink
fix: broken middleware name (#12871)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day authored Apr 15, 2023
1 parent ab3a530 commit 32bef57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,24 @@ export async function preview(

// static assets
const headers = config.preview.headers
const assetServer = sirv(distDir, {
etag: true,
dev: true,
single: config.appType === 'spa',
setHeaders(res) {
if (headers) {
for (const name in headers) {
res.setHeader(name, headers[name]!)
const viteAssetMiddleware = (...args: readonly [any, any?, any?]) =>
sirv(distDir, {
etag: true,
dev: true,
single: config.appType === 'spa',
setHeaders(res) {
if (headers) {
for (const name in headers) {
res.setHeader(name, headers[name]!)
}
}
}
},
shouldServe(filePath) {
return shouldServeFile(filePath, distDir)
},
})
app.use(previewBase, assetServer)
},
shouldServe(filePath) {
return shouldServeFile(filePath, distDir)
},
})(...args)

app.use(previewBase, viteAssetMiddleware)

// apply post server hooks from plugins
postHooks.forEach((fn) => fn && fn())
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function compression() {
// disable Brotli on Node<12.7 where it is unsupported:
if (!zlib.createBrotliCompress) brotli = false

return (req, res, next = noop) => {
return function viteCompressionMiddleware(req, res, next = noop) {
const accept = req.headers['accept-encoding'] + ''
const encoding = ((brotli && accept.match(/\bbr\b/)) ||
(gzip && accept.match(/\bgzip\b/)) ||
Expand Down

0 comments on commit 32bef57

Please sign in to comment.