@middy/http-router 5.0.2 → 5.0.3

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.
Files changed (2) hide show
  1. package/index.js +3 -14
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -5,7 +5,6 @@ const httpRouteHandler = (routes)=>{
5
5
  const enumMethods = methods.concat('ANY');
6
6
  for (const route of routes){
7
7
  let { method, path, handler } = route;
8
- // Prevents `routesType[method][path] = handler` from flagging: This assignment may alter Object.prototype if a malicious '__proto__' string is injected from library input.
9
8
  if (!enumMethods.includes(method)) {
10
9
  throw new Error('Method not allowed', {
11
10
  cause: {
@@ -13,16 +12,13 @@ const httpRouteHandler = (routes)=>{
13
12
  }
14
13
  });
15
14
  }
16
- // remove trailing slash, but not if it's the first one
17
15
  if (path.endsWith('/') && path !== '/') {
18
16
  path = path.substr(0, path.length - 1);
19
17
  }
20
- // Static
21
18
  if (path.indexOf('{') < 0) {
22
19
  attachStaticRoute(method, path, handler, routesStatic);
23
20
  continue;
24
21
  }
25
- // Dynamic
26
22
  attachDynamicRoute(method, path, handler, routesDynamic);
27
23
  }
28
24
  return (event, context, abort)=>{
@@ -35,12 +31,10 @@ const httpRouteHandler = (routes)=>{
35
31
  }
36
32
  });
37
33
  }
38
- // Static
39
34
  const handler = routesStatic[method]?.[path];
40
35
  if (typeof handler !== 'undefined') {
41
36
  return handler(event, context, abort);
42
37
  }
43
- // Dynamic
44
38
  for (const route of routesDynamic[method] ?? []){
45
39
  const match = path.match(route.path);
46
40
  if (match) {
@@ -51,7 +45,6 @@ const httpRouteHandler = (routes)=>{
51
45
  return route.handler(event, context, abort);
52
46
  }
53
47
  }
54
- // Not Found
55
48
  throw createError(404, 'Route does not exist', {
56
49
  cause: {
57
50
  package: '@middy/http-router',
@@ -70,8 +63,7 @@ const methods = [
70
63
  'DELETE',
71
64
  'OPTIONS',
72
65
  'HEAD'
73
- ] // ANY excluded by design
74
- ;
66
+ ];
75
67
  const attachStaticRoute = (method, path, handler, routesType)=>{
76
68
  if (method === 'ANY') {
77
69
  for (const method of methods){
@@ -83,8 +75,7 @@ const attachStaticRoute = (method, path, handler, routesType)=>{
83
75
  routesType[method] = {};
84
76
  }
85
77
  routesType[method][path] = handler;
86
- routesType[method][path + '/'] = handler // Optional `/`
87
- ;
78
+ routesType[method][path + '/'] = handler;
88
79
  };
89
80
  const attachDynamicRoute = (method, path, handler, routesType)=>{
90
81
  if (method === 'ANY') {
@@ -97,15 +88,13 @@ const attachDynamicRoute = (method, path, handler, routesType)=>{
97
88
  routesType[method] = [];
98
89
  }
99
90
  path = path.replace(regexpDynamicWildcards, '/?(?<$1>.*)').replace(regexpDynamicParameters, '/(?<$1>[^/]+)');
100
- path = new RegExp(`^${path}/?$`) // Adds in optional `/`
101
- ;
91
+ path = new RegExp(`^${path}/?$`);
102
92
  routesType[method].push({
103
93
  path,
104
94
  handler
105
95
  });
106
96
  };
107
97
  const pickVersion = (event)=>{
108
- // '1.0' is a safer default
109
98
  return event.version ?? (event.method ? 'vpc' : '1.0');
110
99
  };
111
100
  const getVersionRoute = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-router",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "HTTP event router for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -60,11 +60,11 @@
60
60
  "url": "https://github.com/sponsors/willfarrell"
61
61
  },
62
62
  "dependencies": {
63
- "@middy/util": "5.0.2"
63
+ "@middy/util": "5.0.3"
64
64
  },
65
65
  "devDependencies": {
66
- "@middy/core": "5.0.2",
66
+ "@middy/core": "5.0.3",
67
67
  "@types/aws-lambda": "^8.10.97"
68
68
  },
69
- "gitHead": "6d17e155237022f2a0abd095ac7cd99ebfc7fc71"
69
+ "gitHead": "87660575a7ac2b52e4153c407a4c63c9449dcd0d"
70
70
  }