From 99d579eaa56c622112112bfc123265d6efd622c6 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Fri, 18 May 2018 15:03:29 +0200 Subject: [PATCH] Rewrites are now faster --- lib/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 2113a0a..2b6f5f4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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;