Skip to content

Commit

Permalink
Merge pull request #31 from davemo88/not-catching-all-requests
Browse files Browse the repository at this point in the history
remove wrapping arrow func to handle all requests in middleware
  • Loading branch information
nshen authored May 30, 2024
2 parents 895add8 + 5fe9c14 commit 5e626b9
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,23 @@ function vitePluginWasmPack(
},

configureServer({ middlewares }) {
return () => {
// send 'root/pkg/xxx.wasm' file to user
middlewares.use((req, res, next) => {
if (isString(req.url)) {
const basename = path.basename(req.url);
res.setHeader(
'Cache-Control',
'no-cache, no-store, must-revalidate'
);
const entry = wasmMap.get(basename);
if (basename.endsWith('.wasm') && entry) {
res.writeHead(200, { 'Content-Type': 'application/wasm' });
fs.createReadStream(entry.path).pipe(res);
} else {
next();
}
// send 'root/pkg/xxx.wasm' file to user
middlewares.use((req, res, next) => {
if (isString(req.url)) {
const basename = path.basename(req.url);
res.setHeader(
'Cache-Control',
'no-cache, no-store, must-revalidate'
);
const entry = wasmMap.get(basename);
if (basename.endsWith('.wasm') && entry) {
res.writeHead(200, { 'Content-Type': 'application/wasm' });
fs.createReadStream(entry.path).pipe(res);
} else {
next();
}
});
};
}
});
},

buildEnd() {
Expand Down

0 comments on commit 5e626b9

Please sign in to comment.