@momsfriendlydevco/cowboy 1.0.6 → 1.0.8
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 +17 -4
- package/package.json +1 -1
package/lib/cowboy.js
CHANGED
|
@@ -29,7 +29,9 @@ export class Cowboy {
|
|
|
29
29
|
settings = {
|
|
30
30
|
patchAxios: true,
|
|
31
31
|
pathTidy(path) {
|
|
32
|
-
return path
|
|
32
|
+
return path
|
|
33
|
+
.replace(/^\/api\/\w+/, '/')
|
|
34
|
+
.replace(/^\/+/, '/') // Trim excessive forward slashes
|
|
33
35
|
},
|
|
34
36
|
};
|
|
35
37
|
|
|
@@ -77,11 +79,11 @@ export class Cowboy {
|
|
|
77
79
|
|
|
78
80
|
/**
|
|
79
81
|
* Prepend middleware which will be used for all routes
|
|
80
|
-
* @param {CowboyMiddleware} middleware Middleware to use
|
|
82
|
+
* @param {CowboyMiddleware...} middleware Middleware(s) to use
|
|
81
83
|
* @returns {Cowboy} This chainable Cowboy router instance
|
|
82
84
|
*/
|
|
83
85
|
use(...middleware) {
|
|
84
|
-
this.earlyMiddleware.push(middleware);
|
|
86
|
+
this.earlyMiddleware.push(...middleware);
|
|
85
87
|
return this;
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -120,7 +122,18 @@ export class Cowboy {
|
|
|
120
122
|
router: this,
|
|
121
123
|
pathTidy: this.settings.pathTidy,
|
|
122
124
|
});
|
|
123
|
-
|
|
125
|
+
|
|
126
|
+
// Decode input if we're expecting JSON
|
|
127
|
+
if (cfReq.body) {
|
|
128
|
+
try {
|
|
129
|
+
req.body = await cfReq.json();
|
|
130
|
+
} catch (e) {
|
|
131
|
+
if (debug.enabled) {
|
|
132
|
+
debug('Failed to decode request body as JSON: [[[' + cfReq.body.toString() + ']]]');
|
|
133
|
+
}
|
|
134
|
+
throw new Error('Invalid JSON body');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
124
137
|
|
|
125
138
|
let res = new CowboyResponse();
|
|
126
139
|
debug('Incoming request:', req.toString());
|