@middy/http-router 7.1.2 → 7.1.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/README.md +17 -0
- package/index.d.ts +2 -4
- package/index.js +6 -9
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -30,6 +30,23 @@
|
|
|
30
30
|
<p>You can read the documentation at: <a href="https://middy.js.org/docs/routers/http-router">https://middy.js.org/docs/routers/http-router</a></p>
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install --save @middy/http-router
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Documentation and examples
|
|
41
|
+
|
|
42
|
+
For documentation and examples, refer to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org/docs/routers/http-router).
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Contributing
|
|
46
|
+
|
|
47
|
+
Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
|
|
48
|
+
|
|
49
|
+
|
|
33
50
|
## License
|
|
34
51
|
|
|
35
52
|
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2026 [will Farrell](https://github.com/willfarrell), [Luciano Mammino](https://github.com/lmammino), and [Middy contributors](https://github.com/middyjs/middy/graphs/contributors).
|
package/index.d.ts
CHANGED
|
@@ -25,15 +25,13 @@ export type Method =
|
|
|
25
25
|
export interface Route<TEvent, TResult> {
|
|
26
26
|
method: Method;
|
|
27
27
|
path: string;
|
|
28
|
-
handler:
|
|
29
|
-
| LambdaHandler<TEvent, TResult>
|
|
30
|
-
| MiddyfiedHandler<TEvent, TResult, any, any>;
|
|
28
|
+
handler: LambdaHandler<TEvent, TResult> | MiddyfiedHandler<TEvent, TResult>;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
export type RouteNotFoundResponseFn = (input: {
|
|
34
32
|
method: string;
|
|
35
33
|
path: string;
|
|
36
|
-
}) =>
|
|
34
|
+
}) => unknown;
|
|
37
35
|
|
|
38
36
|
declare function httpRouterHandler<
|
|
39
37
|
TEvent extends
|
package/index.js
CHANGED
|
@@ -22,8 +22,8 @@ const httpRouteHandler = (opts = {}) => {
|
|
|
22
22
|
options ??= opts;
|
|
23
23
|
const { routes, notFoundResponse } = { ...defaults, ...options };
|
|
24
24
|
|
|
25
|
-
const routesStatic =
|
|
26
|
-
const routesDynamic =
|
|
25
|
+
const routesStatic = Object.create(null);
|
|
26
|
+
const routesDynamic = Object.create(null);
|
|
27
27
|
const enumMethods = methods.concat("ANY");
|
|
28
28
|
for (const route of routes) {
|
|
29
29
|
let { method, path, handler } = route;
|
|
@@ -65,17 +65,14 @@ const httpRouteHandler = (opts = {}) => {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// Static
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
) {
|
|
72
|
-
const handler = routesStatic[method][path];
|
|
73
|
-
return handler(event, context, abort);
|
|
68
|
+
const staticHandler = routesStatic[method]?.[path];
|
|
69
|
+
if (staticHandler) {
|
|
70
|
+
return staticHandler(event, context, abort);
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
// Dynamic
|
|
77
74
|
if (Object.hasOwn(routesDynamic, method)) {
|
|
78
|
-
for (const route of routesDynamic[method]
|
|
75
|
+
for (const route of routesDynamic[method]) {
|
|
79
76
|
const match = path.match(route.path);
|
|
80
77
|
if (match) {
|
|
81
78
|
event.pathParameters = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-router",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.3",
|
|
4
4
|
"description": "HTTP event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"url": "https://github.com/sponsors/willfarrell"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@middy/util": "7.1.
|
|
68
|
+
"@middy/util": "7.1.3"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@middy/core": "7.1.
|
|
72
|
-
"@types/aws-lambda": "^8.0.0"
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
"@middy/core": "7.1.3",
|
|
72
|
+
"@types/aws-lambda": "^8.0.0",
|
|
73
|
+
"@types/node": "^22.0.0"
|
|
74
|
+
}
|
|
75
75
|
}
|