@momsfriendlydevco/cowboy 1.0.16 → 1.0.17
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/README.md +1 -1
- package/lib/cowboy.js +7 -1
- package/lib/response.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,7 +106,7 @@ let router = new Cowboy()
|
|
|
106
106
|
Notes:
|
|
107
107
|
* All middleware items are called in sequence - and are async waited-on)
|
|
108
108
|
* If any middleware functions fail the entire chain aborts with an error
|
|
109
|
-
* All middleware functions are called as `(CowboyRequest, CowboyResponse)`
|
|
109
|
+
* All middleware functions are called as `(CowboyRequest, CowboyResponse, Env)`
|
|
110
110
|
* If any middleware functions call `res.end()` (or any of its automatic methods like `res.send()` / `res.sendStatus()`) the chain also aborts successfully
|
|
111
111
|
* If the last middleware function returns a non response object - i.e. the function didn't call `res.send()` its assumed to be a valid output and is automatically wrapped
|
|
112
112
|
|
package/lib/cowboy.js
CHANGED
|
@@ -69,9 +69,11 @@ export class Cowboy {
|
|
|
69
69
|
* @returns {Cowboy} This chainable Cowboy router instance
|
|
70
70
|
*/
|
|
71
71
|
route(methods, paths, ...middleware) {
|
|
72
|
+
let matcher = compileRoutePaths(paths);
|
|
72
73
|
this.routes.push({
|
|
73
74
|
methods: Array.isArray(methods) ? methods : [methods],
|
|
74
|
-
|
|
75
|
+
paths: matcher.paths,
|
|
76
|
+
matcher,
|
|
75
77
|
middleware,
|
|
76
78
|
})
|
|
77
79
|
|
|
@@ -148,6 +150,10 @@ export class Cowboy {
|
|
|
148
150
|
return res.sendStatus(404).toCloudflareResponse(); // No matching route
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
// Populate params
|
|
154
|
+
let firstPathIndex = route.paths.findIndex(re => re.test(req.path));
|
|
155
|
+
req.params = route.paths[firstPathIndex].exec(req.path)?.groups;
|
|
156
|
+
|
|
151
157
|
// Exec route middleware
|
|
152
158
|
let response = await this.execMiddleware({
|
|
153
159
|
req, res, env,
|
package/lib/response.js
CHANGED
|
@@ -99,7 +99,12 @@ export default class CowboyResponse {
|
|
|
99
99
|
status: this.code,
|
|
100
100
|
headers: this.headers,
|
|
101
101
|
};
|
|
102
|
-
console.log('
|
|
102
|
+
console.log('Response', JSON.stringify({
|
|
103
|
+
...cfOptions,
|
|
104
|
+
body:
|
|
105
|
+
typeof this.body == 'string' && this.body.length > 30 ? this.body.substr(0, 50) + '…'
|
|
106
|
+
: this.body,
|
|
107
|
+
}, null, '\t'));
|
|
103
108
|
return new this.CloudflareResponse(this.body, cfOptions);
|
|
104
109
|
}
|
|
105
110
|
}
|