Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken middleware name #12871

Merged
merged 1 commit into from Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 17 additions & 15 deletions packages/vite/src/node/preview.ts
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
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