From c335877d56dc995174a77d5dbb3b21a98cb9b3c7 Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 19 Mar 2024 15:14:12 +0100 Subject: [PATCH] use post middleware --- packages/vite/src/assets.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/assets.ts b/packages/vite/src/assets.ts index d6418a70f..62ad757a1 100644 --- a/packages/vite/src/assets.ts +++ b/packages/vite/src/assets.ts @@ -36,18 +36,20 @@ export function assets(): Plugin { configureServer(server) { mode = server.config.command; publicDir = server.config.publicDir; - server.middlewares.use((req, res, next) => { - if (req.originalUrl?.includes('?')) { - return next(); - } - if (req.originalUrl && req.originalUrl.length > 1) { - const assetUrl = findPublicAsset(req.originalUrl, resolverLoader.resolver); - if (assetUrl) { - return send(req as Readable, assetUrl).pipe(res); + return () => { + server.middlewares.use((req, res, next) => { + if (req.originalUrl?.includes('?')) { + return next(); } - } - return next(); - }); + if (req.originalUrl && req.originalUrl.length > 1) { + const assetUrl = findPublicAsset(req.originalUrl, resolverLoader.resolver); + if (assetUrl) { + return send(req as Readable, assetUrl).pipe(res); + } + } + return next(); + }); + } }, async buildStart() { if (mode !== 'build') return;