@momsfriendlydevco/cowboy 1.0.1 → 1.0.2
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 +18 -1
- package/lib/request.js +1 -1
- package/package.json +1 -1
package/lib/cowboy.js
CHANGED
|
@@ -19,6 +19,20 @@ export class Cowboy {
|
|
|
19
19
|
* @property {Array<CowboyMiddleware>} [middleware] Middleware / resolvers to use for the route, should it match
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* General settings for this Cowboy instance
|
|
25
|
+
*
|
|
26
|
+
* @type {Object}
|
|
27
|
+
* @property {Function} pathTidy Additional tidyup for server request paths, useful if the API does not live at the server root. Defaults to removing a "/api/:worker/" prefix
|
|
28
|
+
*/
|
|
29
|
+
settings = {
|
|
30
|
+
pathTidy(path) {
|
|
31
|
+
return path.replace(/^\/api\/\w+\//, '/');
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
22
36
|
/**
|
|
23
37
|
* List of middleware which will be called on all matching routes
|
|
24
38
|
* @type Array<CowboyMiddleware>
|
|
@@ -93,7 +107,10 @@ export class Cowboy {
|
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
// Create basic [req]uest / [res]ponse objects
|
|
96
|
-
let req = new CowboyRequest(cfReq, {
|
|
110
|
+
let req = new CowboyRequest(cfReq, {
|
|
111
|
+
router: this,
|
|
112
|
+
pathTidy: this.settings.pathTidy,
|
|
113
|
+
});
|
|
97
114
|
let res = new CowboyResponse();
|
|
98
115
|
|
|
99
116
|
// Exec all earlyMiddleware - every time
|
package/lib/request.js
CHANGED