@momsfriendlydevco/cowboy 1.0.6 → 1.0.7
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/cowboy.js +14 -3
- package/package.json +1 -1
package/lib/cowboy.js
CHANGED
|
@@ -77,11 +77,11 @@ export class Cowboy {
|
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Prepend middleware which will be used for all routes
|
|
80
|
-
* @param {CowboyMiddleware} middleware Middleware to use
|
|
80
|
+
* @param {CowboyMiddleware...} middleware Middleware(s) to use
|
|
81
81
|
* @returns {Cowboy} This chainable Cowboy router instance
|
|
82
82
|
*/
|
|
83
83
|
use(...middleware) {
|
|
84
|
-
this.earlyMiddleware.push(middleware);
|
|
84
|
+
this.earlyMiddleware.push(...middleware);
|
|
85
85
|
return this;
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -120,7 +120,18 @@ export class Cowboy {
|
|
|
120
120
|
router: this,
|
|
121
121
|
pathTidy: this.settings.pathTidy,
|
|
122
122
|
});
|
|
123
|
-
|
|
123
|
+
|
|
124
|
+
// Decode input if we're expecting JSON
|
|
125
|
+
if (cfReq.body) {
|
|
126
|
+
try {
|
|
127
|
+
req.body = await cfReq.json();
|
|
128
|
+
} catch (e) {
|
|
129
|
+
if (debug.enabled) {
|
|
130
|
+
debug('Failed to decode request body as JSON: [[[' + cfReq.body.toString() + ']]]');
|
|
131
|
+
}
|
|
132
|
+
throw new Error('Invalid JSON body');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
124
135
|
|
|
125
136
|
let res = new CowboyResponse();
|
|
126
137
|
debug('Incoming request:', req.toString());
|