@momsfriendlydevco/cowboy 1.0.11 → 1.0.14
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/request.js
CHANGED
|
@@ -73,7 +73,7 @@ export default class CowboyRequest {
|
|
|
73
73
|
* @returns {Promise} A promise which will resolve when the body has been parsed
|
|
74
74
|
*/
|
|
75
75
|
async parseBody(forceType) {
|
|
76
|
-
let type = (forceType || this.headers['content-type'])
|
|
76
|
+
let type = (forceType || this.headers['content-type'] || '')
|
|
77
77
|
.replace(/^([a-z\-\/]+).*$/, '$1'); // Scrap everything after the mime
|
|
78
78
|
|
|
79
79
|
switch (type) {
|
|
@@ -107,7 +107,7 @@ export default class CowboyRequest {
|
|
|
107
107
|
throw new Error('Invalid text body');
|
|
108
108
|
}
|
|
109
109
|
default:
|
|
110
|
-
debug('
|
|
110
|
+
debug('Empty Body Payload');
|
|
111
111
|
this.body = {};
|
|
112
112
|
}
|
|
113
113
|
}
|
package/middleware/validate.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import joyful from '@momsfriendlydevco/joyful';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Run a Joi / Joyful validation function against a specific subkey within `req
|
|
5
|
+
*
|
|
6
|
+
* @param {String} subkey The subkey to run against
|
|
7
|
+
* @param {Function|Object} Callback to use with Joyful to validate with
|
|
8
|
+
* @returns {Void} Either a successful middleware cycle (if validatio succeeds) or a call to `res.status(400)` if failed
|
|
9
|
+
*/
|
|
3
10
|
export default function CowboyMiddlewareValidate(subkey, validator) {
|
|
4
11
|
return (req, res) => {
|
|
5
|
-
let joyfulResult = joyful(
|
|
6
|
-
[subkey]: validator,
|
|
7
|
-
});
|
|
12
|
+
let joyfulResult = joyful(req[subkey], validator);
|
|
8
13
|
|
|
9
14
|
if (joyfulResult !== true) { // Failed body validation?
|
|
10
15
|
return res
|