@middy/ws-router 5.1.0 → 5.2.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 +31 -28
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import { createError } from '@middy/util'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { createError } from '@middy/util'
|
|
2
|
+
|
|
3
|
+
const wsRouteHandler = (routes) => {
|
|
4
|
+
const routesStatic = {}
|
|
5
|
+
for (const route of routes) {
|
|
6
|
+
const { routeKey, handler } = route
|
|
7
|
+
|
|
8
|
+
// Static
|
|
9
|
+
routesStatic[routeKey] = handler
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return (event, context, abort) => {
|
|
13
|
+
const { routeKey } = event.requestContext ?? {}
|
|
14
|
+
if (!routeKey) {
|
|
15
|
+
throw new Error('Unknown WebSocket event format', {
|
|
16
|
+
cause: { package: '@middy/ws-router' }
|
|
17
|
+
})
|
|
7
18
|
}
|
|
8
|
-
return (event, context, abort)=>{
|
|
9
|
-
const { routeKey } = event.requestContext ?? {};
|
|
10
|
-
if (!routeKey) {
|
|
11
|
-
throw new Error('Unknown WebSocket event format', {
|
|
12
|
-
cause: {
|
|
13
|
-
package: '@middy/ws-router'
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const handler = routesStatic[routeKey];
|
|
18
|
-
if (typeof handler !== 'undefined') {
|
|
19
|
-
return handler(event, context, abort);
|
|
20
|
-
}
|
|
21
|
-
throw createError(404, 'Route does not exist', {
|
|
22
|
-
cause: {
|
|
23
|
-
package: '@middy/ws-router',
|
|
24
|
-
data: routeKey
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export default wsRouteHandler;
|
|
30
19
|
|
|
20
|
+
// Static
|
|
21
|
+
const handler = routesStatic[routeKey]
|
|
22
|
+
if (typeof handler !== 'undefined') {
|
|
23
|
+
return handler(event, context, abort)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Not Found
|
|
27
|
+
throw createError(404, 'Route does not exist', {
|
|
28
|
+
cause: { package: '@middy/ws-router', data: routeKey }
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default wsRouteHandler
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/ws-router",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "WebSocket 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.
|
|
63
|
+
"@middy/util": "5.2.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@middy/core": "5.
|
|
66
|
+
"@middy/core": "5.2.0",
|
|
67
67
|
"@types/aws-lambda": "^8.10.100"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "2d9096a49cd8fb62359517be96d6c93609df41f0"
|
|
70
70
|
}
|