Skip to content

Commit

Permalink
Rewrites are now faster
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed May 18, 2018
1 parent f331952 commit 99d579e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ const applyRewrites = (requestPath, rewrites) => {
return requestPath;
}

const rewrite = rewrites.find(({source}) => toRegExp(source).test(requestPath));
for (let index = 0; index < rewrites.length; index++) {
const {source, destination} = rewrites[index];

if (rewrite) {
return applyRewrites(slasher(rewrite.destination), rewrites);
if (toRegExp(source).test(requestPath)) {
return applyRewrites(slasher(destination), rewrites);
}
}

return requestPath;
Expand Down

0 comments on commit 99d579e

Please sign in to comment.