Skip to content

Commit

Permalink
fix: remove restriction on nodeReq in compressMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
magne4000 committed Nov 25, 2024
1 parent 1122909 commit 40315e7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/vike-node/src/runtime/vike-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ async function renderPage({
}

export const compressMiddleware = ((options?) => async (request, _context, runtime: any) => {
const nodeReq: IncomingMessage | undefined = runtime.req
const compressionType = options?.compress ?? !isVercel()
const compressMiddlewareInternal = compressMiddlewareFactory()(request)

return async (response) => {
if (!globalStore.isDev && nodeReq) {
const isAsset = nodeReq.url?.startsWith('/assets/')
if (!globalStore.isDev) {
const isAsset = new URL(request.url).pathname.startsWith('/assets/')
const shouldCompressResponse = compressionType === true || (compressionType === 'static' && isAsset)
if (shouldCompressResponse) {
return compressMiddlewareInternal(response)
Expand Down

0 comments on commit 40315e7

Please sign in to comment.