Skip to content

Commit 32bef57

Browse files
authoredApr 15, 2023
fix: broken middleware name (#12871)
1 parent ab3a530 commit 32bef57

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed
 

‎packages/vite/src/node/preview.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,24 @@ export async function preview(
161161

162162
// static assets
163163
const headers = config.preview.headers
164-
const assetServer = sirv(distDir, {
165-
etag: true,
166-
dev: true,
167-
single: config.appType === 'spa',
168-
setHeaders(res) {
169-
if (headers) {
170-
for (const name in headers) {
171-
res.setHeader(name, headers[name]!)
164+
const viteAssetMiddleware = (...args: readonly [any, any?, any?]) =>
165+
sirv(distDir, {
166+
etag: true,
167+
dev: true,
168+
single: config.appType === 'spa',
169+
setHeaders(res) {
170+
if (headers) {
171+
for (const name in headers) {
172+
res.setHeader(name, headers[name]!)
173+
}
172174
}
173-
}
174-
},
175-
shouldServe(filePath) {
176-
return shouldServeFile(filePath, distDir)
177-
},
178-
})
179-
app.use(previewBase, assetServer)
175+
},
176+
shouldServe(filePath) {
177+
return shouldServeFile(filePath, distDir)
178+
},
179+
})(...args)
180+
181+
app.use(previewBase, viteAssetMiddleware)
180182

181183
// apply post server hooks from plugins
182184
postHooks.forEach((fn) => fn && fn())

‎packages/vite/src/node/server/middlewares/compression.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function compression() {
2525
// disable Brotli on Node<12.7 where it is unsupported:
2626
if (!zlib.createBrotliCompress) brotli = false
2727

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

0 commit comments

Comments
 (0)
Please sign in to comment.