@middy/http-router 5.4.6 → 5.5.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.js +16 -4
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { createError } from '@middy/util'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const defaults = {
|
|
4
|
+
routes: [],
|
|
5
|
+
notFoundResponse: ({ method, path }) => {
|
|
6
|
+
const err = createError(404, 'Route does not exist', {
|
|
7
|
+
cause: { package: '@middy/http-router', data: { method, path } }
|
|
8
|
+
})
|
|
9
|
+
throw err
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const httpRouteHandler = (opts = {}) => {
|
|
13
|
+
if (Array.isArray(opts)) {
|
|
14
|
+
opts = { routes: opts }
|
|
15
|
+
}
|
|
16
|
+
const { routes, notFoundResponse } = { ...defaults, ...opts }
|
|
17
|
+
|
|
4
18
|
const routesStatic = {}
|
|
5
19
|
const routesDynamic = {}
|
|
6
20
|
const enumMethods = methods.concat('ANY')
|
|
@@ -56,9 +70,7 @@ const httpRouteHandler = (routes) => {
|
|
|
56
70
|
}
|
|
57
71
|
|
|
58
72
|
// Not Found
|
|
59
|
-
|
|
60
|
-
cause: { package: '@middy/http-router', data: path }
|
|
61
|
-
})
|
|
73
|
+
return notFoundResponse({ method, path })
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
76
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-router",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "HTTP event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"url": "https://github.com/sponsors/willfarrell"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@middy/util": "5.
|
|
63
|
+
"@middy/util": "5.5.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@middy/core": "5.
|
|
66
|
+
"@middy/core": "5.5.0",
|
|
67
67
|
"@types/aws-lambda": "^8.10.97"
|
|
68
68
|
},
|
|
69
69
|
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|