cpeak 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +6 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -32,18 +32,21 @@ class CPeak {
|
|
|
32
32
|
res.end(JSON.stringify(data));
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
const urlWithoutParams = req.url.split("?")[0];
|
|
36
|
+
req.params = new URLSearchParams(req.url.split("?")[1]);
|
|
37
|
+
|
|
35
38
|
// Run all the middleware functions before we run the corresponding route
|
|
36
39
|
const runMiddleware = (req, res, middleware, index) => {
|
|
37
40
|
// Out exit point...
|
|
38
41
|
if (index === middleware.length) {
|
|
39
42
|
// If the routes object does not have a key of req.method + req.url, return 404
|
|
40
|
-
if (!this.routes[req.method.toLocaleLowerCase() +
|
|
43
|
+
if (!this.routes[req.method.toLocaleLowerCase() + urlWithoutParams]) {
|
|
41
44
|
return res
|
|
42
45
|
.status(404)
|
|
43
|
-
.json({ error: `Cannot ${req.method} ${
|
|
46
|
+
.json({ error: `Cannot ${req.method} ${urlWithoutParams}` });
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
this.routes[req.method.toLowerCase() +
|
|
49
|
+
this.routes[req.method.toLowerCase() + urlWithoutParams](req, res);
|
|
47
50
|
} else {
|
|
48
51
|
middleware[index](req, res, () => {
|
|
49
52
|
runMiddleware(req, res, middleware, index + 1);
|