@middy/http-router 7.2.2 → 7.2.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.
- package/index.js +17 -8
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -54,14 +54,20 @@ const httpRouteHandler = (opts = {}) => {
|
|
|
54
54
|
const { method, path } = getVersionRoute[pickVersion(event)](event);
|
|
55
55
|
|
|
56
56
|
if (!method) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
throw new Error(
|
|
58
|
+
"Unknown HTTP event format: missing HTTP method. Expected 'httpMethod' (v1), 'requestContext.http.method' (v2), or 'method' (VPC)",
|
|
59
|
+
{
|
|
60
|
+
cause: { package: "@middy/http-router", data: { method } },
|
|
61
|
+
},
|
|
62
|
+
);
|
|
60
63
|
}
|
|
61
64
|
if (!path) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
throw new Error(
|
|
66
|
+
"Unknown HTTP event format: missing path. Expected 'path' (v1), 'requestContext.http.path' (v2), or 'raw_path' (VPC)",
|
|
67
|
+
{
|
|
68
|
+
cause: { package: "@middy/http-router", data: { path } },
|
|
69
|
+
},
|
|
70
|
+
);
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
// Static
|
|
@@ -90,8 +96,9 @@ const httpRouteHandler = (opts = {}) => {
|
|
|
90
96
|
return handler;
|
|
91
97
|
};
|
|
92
98
|
|
|
93
|
-
const
|
|
94
|
-
const
|
|
99
|
+
const regExpEscapeChars = /[.+?^${}()|[\]\\]/g;
|
|
100
|
+
const regExpDynamicWildcards = /\/\\\{(proxy)\\\+\\\}$/;
|
|
101
|
+
const regExpDynamicParameters = /\/\\\{([^/]+)\\\}/g;
|
|
95
102
|
|
|
96
103
|
const attachStaticRoute = (method, path, handler, routesType) => {
|
|
97
104
|
if (method === "ANY") {
|
|
@@ -101,6 +108,7 @@ const attachStaticRoute = (method, path, handler, routesType) => {
|
|
|
101
108
|
return;
|
|
102
109
|
}
|
|
103
110
|
routesType[method] ??= {};
|
|
111
|
+
// TODO v8 when duplicates throw error
|
|
104
112
|
routesType[method][path] = handler;
|
|
105
113
|
routesType[method][`${path}/`] = handler; // Optional `/`
|
|
106
114
|
};
|
|
@@ -114,6 +122,7 @@ const attachDynamicRoute = (method, path, handler, routesType) => {
|
|
|
114
122
|
}
|
|
115
123
|
routesType[method] ??= [];
|
|
116
124
|
const pathPartialRegExp = path
|
|
125
|
+
.replace(regExpEscapeChars, "\\$&")
|
|
117
126
|
.replace(regExpDynamicWildcards, "/?(?<$1>.*)")
|
|
118
127
|
.replace(regExpDynamicParameters, "/(?<$1>[^/]+)");
|
|
119
128
|
// SAST Skipped: Not accessible by users
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-router",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.3",
|
|
4
4
|
"description": "HTTP event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"url": "https://github.com/sponsors/willfarrell"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@middy/util": "7.2.
|
|
68
|
+
"@middy/util": "7.2.3"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@middy/core": "7.2.
|
|
71
|
+
"@middy/core": "7.2.3",
|
|
72
72
|
"@types/aws-lambda": "^8.0.0",
|
|
73
73
|
"@types/node": "^22.0.0"
|
|
74
74
|
}
|