@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.
Files changed (2) hide show
  1. package/lib/cowboy.js +14 -3
  2. 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
- if (cfReq.body) req.body = await cfReq.json();
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());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momsfriendlydevco/cowboy",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Wrapper around Cloudflare Wrangler to provide a more Express-like experience",
5
5
  "scripts": {
6
6
  "lint": "eslint ."