Skip to content

Commit

Permalink
Redirect Chrome specific source map URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Jul 4, 2021
1 parent e0bd038 commit 1f2aaf9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/wmr/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ export default async function server({ cwd, root, overlayDir, middleware, http2,

app.use('/@npm', npmMiddleware({ alias, optimize, cwd }));

// Chrome devtools often adds `?%20[sm]` to the url
// to differentiate between sourcemaps
app.use((req, res, next) => {
if (/\?%20\[sm\]$/.test(req.url)) {
res.writeHead(302, {
Location: req.url.replace('?%20[sm]', '.map')
});
res.end();
return;
}

next();
});

if (middleware) {
app.use(...middleware);
}
Expand Down

0 comments on commit 1f2aaf9

Please sign in to comment.