@momsfriendlydevco/cowboy 1.0.17 → 1.0.19
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 +4 -0
- package/lib/response.js +24 -1
- package/middleware/index.js +2 -0
- package/middleware/validateHeaders.js +5 -0
- package/package.json +2 -2
package/README.md
CHANGED
package/lib/response.js
CHANGED
|
@@ -25,6 +25,24 @@ export default class CowboyResponse {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* ExpressJS-like type setter and shortcut function
|
|
30
|
+
* Recognises various shorthand types or defaults to setting a MIME type
|
|
31
|
+
* @param {String} type The type string to set, can be a shorthand string or a mime type
|
|
32
|
+
* @returns {CowboyResponse} This chainable instance
|
|
33
|
+
*/
|
|
34
|
+
type(type) {
|
|
35
|
+
switch (type) {
|
|
36
|
+
case 'html': return this.set('Content-Type', 'text/html');
|
|
37
|
+
case 'json': return this.set('Content-Type', 'application/json');
|
|
38
|
+
case 'text': return this.set('Content-Type', 'text/plain');
|
|
39
|
+
default:
|
|
40
|
+
if (!/\//.test(type)) throw new Error(`Shorthand type "${type}" is not recognised and does not look like a valid mime type`);
|
|
41
|
+
return this.set('Content-Type', type);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
28
46
|
/**
|
|
29
47
|
* Send data and (optionally) mark the response as complete
|
|
30
48
|
* @param {*} data The data to transmit
|
|
@@ -34,7 +52,12 @@ export default class CowboyResponse {
|
|
|
34
52
|
send(data, end = true) {
|
|
35
53
|
if (this.code === null) this.code = 200; // Assume OK if not told otherwise
|
|
36
54
|
|
|
37
|
-
if (
|
|
55
|
+
if (
|
|
56
|
+
typeof data == 'string'
|
|
57
|
+
|| data instanceof FormData
|
|
58
|
+
|| data instanceof ReadableStream
|
|
59
|
+
|| data instanceof URLSearchParams
|
|
60
|
+
) {
|
|
38
61
|
this.body = data;
|
|
39
62
|
} else {
|
|
40
63
|
this.body = JSON.stringify(data);
|
package/middleware/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import cors from '#middleware/cors';
|
|
2
2
|
import validate from '#middleware/validate';
|
|
3
3
|
import validateBody from '#middleware/validateBody';
|
|
4
|
+
import validateHeaders from '#middleware/validateHeaders';
|
|
4
5
|
import validateParams from '#middleware/validateParams';
|
|
5
6
|
import validateQuery from '#middleware/validateQuery';
|
|
6
7
|
|
|
@@ -8,6 +9,7 @@ export default {
|
|
|
8
9
|
cors,
|
|
9
10
|
validate,
|
|
10
11
|
validateBody,
|
|
12
|
+
validateHeaders,
|
|
11
13
|
validateParams,
|
|
12
14
|
validateQuery,
|
|
13
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momsfriendlydevco/cowboy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "Wrapper around Cloudflare Wrangler to provide a more Express-like experience",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint ."
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@momsfriendlydevco/joyful": "^1.0.1",
|
|
39
|
-
"@momsfriendlydevco/path-match": "^1.
|
|
39
|
+
"@momsfriendlydevco/path-match": "^1.1.0",
|
|
40
40
|
"toml": "^3.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|