@momsfriendlydevco/cowboy 1.0.15 → 1.0.16

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 CHANGED
@@ -2,6 +2,7 @@ import debug from '#lib/debug';
2
2
  import CowboyMiddleware from '#middleware';
3
3
  import CowboyRequest from '#lib/request';
4
4
  import CowboyResponse from '#lib/response';
5
+ import {compile as compileRoutePaths} from '@momsfriendlydevco/path-match';
5
6
 
6
7
  export class Cowboy {
7
8
  /**
@@ -70,9 +71,10 @@ export class Cowboy {
70
71
  route(methods, paths, ...middleware) {
71
72
  this.routes.push({
72
73
  methods: Array.isArray(methods) ? methods : [methods],
73
- paths: Array.isArray(paths) ? paths : [paths],
74
+ matcher: compileRoutePaths(paths),
74
75
  middleware,
75
76
  })
77
+
76
78
  return this;
77
79
  }
78
80
 
@@ -96,11 +98,7 @@ export class Cowboy {
96
98
  resolve(req) {
97
99
  return this.routes.find(route =>
98
100
  route.methods.includes(req.method) // Method matches
99
- && route.paths.some(path => // Path matches
100
- typeof path == 'string' ? req.path == path
101
- : path instanceof RegExp ? path.test(req.path)
102
- : (()=> { throw new Error('Path is not a String or RegExp') })()
103
- )
101
+ && route.matcher.isMatch(req.path)
104
102
  );
105
103
  }
106
104
 
package/lib/request.js CHANGED
@@ -54,6 +54,9 @@ export default class CowboyRequest {
54
54
  this.hostname = url.hostname;
55
55
  this.query = Object.fromEntries(url.searchParams);
56
56
 
57
+ this.routePath = ''; // Eventually matching routePath segment
58
+ this.params = {}; // Set empty object for path extraction
59
+
57
60
  // Slurp the headers
58
61
  this.headers = Object.fromEntries(cfReq.headers.entries());
59
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momsfriendlydevco/cowboy",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Wrapper around Cloudflare Wrangler to provide a more Express-like experience",
5
5
  "scripts": {
6
6
  "lint": "eslint ."
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@momsfriendlydevco/joyful": "^1.0.1",
39
+ "@momsfriendlydevco/path-match": "^1.0.0",
39
40
  "toml": "^3.0.0"
40
41
  },
41
42
  "devDependencies": {