From f15d856059a6f30a86b455be992ca59ca8b1920c Mon Sep 17 00:00:00 2001 From: unreadable Date: Sun, 3 Mar 2019 16:07:35 +0200 Subject: [PATCH 1/7] Fix TypeError in strict mode In strict mode, the following error will be thrown: "TypeError: Cannot set property path of # which has only a getter", this should fix it. --- packages/polka/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/polka/index.js b/packages/polka/index.js index f32a29c..34c126b 100644 --- a/packages/polka/index.js +++ b/packages/polka/index.js @@ -14,7 +14,6 @@ function value(x) { function mutate(str, req) { req.url = req.url.substring(str.length) || '/'; - req.path = req.path.substring(str.length) || '/'; } function onError(err, req, res, next) { @@ -71,7 +70,7 @@ class Polka extends Router { info = info || this.parse(req); let fns=[], arr=this.wares, obj=this.find(req.method, info.pathname); req.originalUrl = req.originalUrl || req.url; - let base = value(req.path = info.pathname); + let base = value(info.pathname); if (this.bwares[base] !== void 0) { arr = arr.concat(this.bwares[base]); } From f6f44593140c1048cf0f4f17a0f25b9816198b64 Mon Sep 17 00:00:00 2001 From: unreadable Date: Sun, 3 Mar 2019 17:57:42 +0200 Subject: [PATCH 2/7] Update index.js --- packages/polka/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/polka/index.js b/packages/polka/index.js index 34c126b..fdc1fc6 100644 --- a/packages/polka/index.js +++ b/packages/polka/index.js @@ -14,6 +14,7 @@ function value(x) { function mutate(str, req) { req.url = req.url.substring(str.length) || '/'; + req.path = req.path.substring(str.length) || '/'; } function onError(err, req, res, next) { From a3b4f848b2d08d715a862df3f31f704b1761ee95 Mon Sep 17 00:00:00 2001 From: unreadable Date: Sun, 3 Mar 2019 18:29:01 +0200 Subject: [PATCH 3/7] Update index.js --- packages/polka/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/polka/index.js b/packages/polka/index.js index fdc1fc6..5436ba0 100644 --- a/packages/polka/index.js +++ b/packages/polka/index.js @@ -71,7 +71,15 @@ class Polka extends Router { info = info || this.parse(req); let fns=[], arr=this.wares, obj=this.find(req.method, info.pathname); req.originalUrl = req.originalUrl || req.url; - let base = value(info.pathname); + try { + req.path = info.pathname + } catch (e) { + Object.defineProperty(req, 'path', { + writeable: false, + value: info.pathname + }); + } + let base = value(req.path); if (this.bwares[base] !== void 0) { arr = arr.concat(this.bwares[base]); } From 7e08e4a834827011058cd687a52501221a1f2ab6 Mon Sep 17 00:00:00 2001 From: unreadable Date: Sun, 3 Mar 2019 18:44:17 +0200 Subject: [PATCH 4/7] add missing ";" --- packages/polka/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/polka/index.js b/packages/polka/index.js index 5436ba0..e8ba985 100644 --- a/packages/polka/index.js +++ b/packages/polka/index.js @@ -72,7 +72,7 @@ class Polka extends Router { let fns=[], arr=this.wares, obj=this.find(req.method, info.pathname); req.originalUrl = req.originalUrl || req.url; try { - req.path = info.pathname + req.path = info.pathname; } catch (e) { Object.defineProperty(req, 'path', { writeable: false, From 14179b9985699b0968b6865885783a4d6f04869e Mon Sep 17 00:00:00 2001 From: unreadable Date: Mon, 4 Mar 2019 13:17:13 +0200 Subject: [PATCH 5/7] replace try/catch block --- packages/polka/index.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/polka/index.js b/packages/polka/index.js index e8ba985..8310e80 100644 --- a/packages/polka/index.js +++ b/packages/polka/index.js @@ -71,14 +71,7 @@ class Polka extends Router { info = info || this.parse(req); let fns=[], arr=this.wares, obj=this.find(req.method, info.pathname); req.originalUrl = req.originalUrl || req.url; - try { - req.path = info.pathname; - } catch (e) { - Object.defineProperty(req, 'path', { - writeable: false, - value: info.pathname - }); - } + if (!req.path) req.path = info.pathname; let base = value(req.path); if (this.bwares[base] !== void 0) { arr = arr.concat(this.bwares[base]); From a693d13e4ee0e6175d869da21b6a768ca945c45f Mon Sep 17 00:00:00 2001 From: unreadable Date: Mon, 4 Mar 2019 17:05:13 +0200 Subject: [PATCH 6/7] Update index.js --- packages/polka/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/polka/index.js b/packages/polka/index.js index 8310e80..548cb43 100644 --- a/packages/polka/index.js +++ b/packages/polka/index.js @@ -71,7 +71,10 @@ class Polka extends Router { info = info || this.parse(req); let fns=[], arr=this.wares, obj=this.find(req.method, info.pathname); req.originalUrl = req.originalUrl || req.url; - if (!req.path) req.path = info.pathname; + Object.defineProperty(req, 'path', { + writeable: false, + value: info.pathname + }); let base = value(req.path); if (this.bwares[base] !== void 0) { arr = arr.concat(this.bwares[base]); From 79f18641ac3c28b875b22ed7bb5e736df3c03560 Mon Sep 17 00:00:00 2001 From: unreadable Date: Mon, 4 Mar 2019 17:13:34 +0200 Subject: [PATCH 7/7] Update index.js --- packages/polka/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/polka/index.js b/packages/polka/index.js index 548cb43..8310e80 100644 --- a/packages/polka/index.js +++ b/packages/polka/index.js @@ -71,10 +71,7 @@ class Polka extends Router { info = info || this.parse(req); let fns=[], arr=this.wares, obj=this.find(req.method, info.pathname); req.originalUrl = req.originalUrl || req.url; - Object.defineProperty(req, 'path', { - writeable: false, - value: info.pathname - }); + if (!req.path) req.path = info.pathname; let base = value(req.path); if (this.bwares[base] !== void 0) { arr = arr.concat(this.bwares[base]);