@middy/http-router 3.4.0 → 3.6.0
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/index.cjs +8 -4
- package/index.js +8 -4
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(module, "exports", {
|
|
|
7
7
|
get: ()=>_default
|
|
8
8
|
});
|
|
9
9
|
const _util = require("@middy/util");
|
|
10
|
+
var _event;
|
|
10
11
|
const httpRouteHandler = (routes)=>{
|
|
11
12
|
const routesStatic = {};
|
|
12
13
|
const routesDynamic = {};
|
|
@@ -35,7 +36,9 @@ const httpRouteHandler = (routes)=>{
|
|
|
35
36
|
return handler(event, context, abort);
|
|
36
37
|
}
|
|
37
38
|
for (const route of routesDynamic[method] ?? []){
|
|
38
|
-
|
|
39
|
+
const match = path.match(route.path);
|
|
40
|
+
if (match) {
|
|
41
|
+
(_event = event).pathParameters ?? (_event.pathParameters = match.groups);
|
|
39
42
|
return route.handler(event, context, abort);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -43,7 +46,7 @@ const httpRouteHandler = (routes)=>{
|
|
|
43
46
|
};
|
|
44
47
|
};
|
|
45
48
|
const regexpDynamicWildcards = /\/\{proxy\+\}$/;
|
|
46
|
-
const regexpDynamicParameters = /\/\{[^/]
|
|
49
|
+
const regexpDynamicParameters = /\/\{([^/]+)\}/g;
|
|
47
50
|
const methods = [
|
|
48
51
|
'GET',
|
|
49
52
|
'POST',
|
|
@@ -63,6 +66,7 @@ const attachStaticRoute = (method, path, handler, routesType)=>{
|
|
|
63
66
|
routesType[method] = {};
|
|
64
67
|
}
|
|
65
68
|
routesType[method][path] = handler;
|
|
69
|
+
routesType[method][path + '/'] = handler;
|
|
66
70
|
};
|
|
67
71
|
const attachDynamicRoute = (method, path, handler, routesType)=>{
|
|
68
72
|
if (method === 'ANY') {
|
|
@@ -74,8 +78,8 @@ const attachDynamicRoute = (method, path, handler, routesType)=>{
|
|
|
74
78
|
if (!routesType[method]) {
|
|
75
79
|
routesType[method] = [];
|
|
76
80
|
}
|
|
77
|
-
path = path.replace(regexpDynamicWildcards, '
|
|
78
|
-
path = new RegExp(`^${path}
|
|
81
|
+
path = path.replace(regexpDynamicWildcards, '/?(.*)').replace(regexpDynamicParameters, '/(?<$1>[^/]+)');
|
|
82
|
+
path = new RegExp(`^${path}/?$`);
|
|
79
83
|
routesType[method].push({
|
|
80
84
|
path,
|
|
81
85
|
handler
|
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _event;
|
|
1
2
|
import { createError } from '@middy/util';
|
|
2
3
|
const httpRouteHandler = (routes)=>{
|
|
3
4
|
const routesStatic = {};
|
|
@@ -27,7 +28,9 @@ const httpRouteHandler = (routes)=>{
|
|
|
27
28
|
return handler(event, context, abort);
|
|
28
29
|
}
|
|
29
30
|
for (const route of routesDynamic[method] ?? []){
|
|
30
|
-
|
|
31
|
+
const match = path.match(route.path);
|
|
32
|
+
if (match) {
|
|
33
|
+
(_event = event).pathParameters ?? (_event.pathParameters = match.groups);
|
|
31
34
|
return route.handler(event, context, abort);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
@@ -35,7 +38,7 @@ const httpRouteHandler = (routes)=>{
|
|
|
35
38
|
};
|
|
36
39
|
};
|
|
37
40
|
const regexpDynamicWildcards = /\/\{proxy\+\}$/;
|
|
38
|
-
const regexpDynamicParameters = /\/\{[^/]
|
|
41
|
+
const regexpDynamicParameters = /\/\{([^/]+)\}/g;
|
|
39
42
|
const methods = [
|
|
40
43
|
'GET',
|
|
41
44
|
'POST',
|
|
@@ -55,6 +58,7 @@ const attachStaticRoute = (method, path, handler, routesType)=>{
|
|
|
55
58
|
routesType[method] = {};
|
|
56
59
|
}
|
|
57
60
|
routesType[method][path] = handler;
|
|
61
|
+
routesType[method][path + '/'] = handler;
|
|
58
62
|
};
|
|
59
63
|
const attachDynamicRoute = (method, path, handler, routesType)=>{
|
|
60
64
|
if (method === 'ANY') {
|
|
@@ -66,8 +70,8 @@ const attachDynamicRoute = (method, path, handler, routesType)=>{
|
|
|
66
70
|
if (!routesType[method]) {
|
|
67
71
|
routesType[method] = [];
|
|
68
72
|
}
|
|
69
|
-
path = path.replace(regexpDynamicWildcards, '
|
|
70
|
-
path = new RegExp(`^${path}
|
|
73
|
+
path = path.replace(regexpDynamicWildcards, '/?(.*)').replace(regexpDynamicParameters, '/(?<$1>[^/]+)');
|
|
74
|
+
path = new RegExp(`^${path}/?$`);
|
|
71
75
|
routesType[method].push({
|
|
72
76
|
path,
|
|
73
77
|
handler
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-router",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "HTTP event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://middy.js.org",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@middy/util": "3.
|
|
65
|
+
"@middy/util": "3.6.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@middy/core": "3.
|
|
68
|
+
"@middy/core": "3.6.0",
|
|
69
69
|
"@types/aws-lambda": "^8.10.97"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "f45a017c3052f7c238eea88b98fee18a816dd317"
|
|
72
72
|
}
|