Skip to content

Commit

Permalink
use post middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Mar 19, 2024
1 parent 5af57e5 commit c335877
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/vite/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c335877

Please sign in to comment.