@middy/ws-router 4.0.0 → 4.0.1
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 +0 -67
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -36,73 +36,6 @@
|
|
|
36
36
|
<p>You can read the documentation at: <a href="https://middy.js.org/docs/routers/ws-router">https://middy.js.org/docs/routers/ws-router</a></p>
|
|
37
37
|
</div>
|
|
38
38
|
|
|
39
|
-
This handler can route to requests to one of a nested handler based on `routeKey` of an WebSocket event from API Gateway (WebSocket).
|
|
40
|
-
|
|
41
|
-
## Install
|
|
42
|
-
|
|
43
|
-
To install this middleware you can use NPM:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
npm install --save @middy/ws-router
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Options
|
|
50
|
-
- `routes` (array[{method, path, handler}]) (required): Array of route objects.
|
|
51
|
-
- `routeKey` (string) (required): AWS formatted route key. ie `$connect`, `$disconnect`, `$default`
|
|
52
|
-
- `handler` (function) (required): Any `handler(event, context, {signal})` function
|
|
53
|
-
|
|
54
|
-
NOTES:
|
|
55
|
-
- Errors should be handled as part of the router middleware stack **or** the lambdaHandler middleware stack. Handled errors in the later will trigger the `after` middleware stack of the former.
|
|
56
|
-
- Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack.
|
|
57
|
-
|
|
58
|
-
## Sample usage
|
|
59
|
-
|
|
60
|
-
```javascript
|
|
61
|
-
import middy from '@middy/core'
|
|
62
|
-
import wsRouterHandler from '@middy/ws-router'
|
|
63
|
-
import wsResponseMiddleware from '@middy/ws-response'
|
|
64
|
-
import validatorMiddleware from '@middy/validator'
|
|
65
|
-
|
|
66
|
-
const connectHandler = middy()
|
|
67
|
-
.use(validatorMiddleware({eventSchema: {...} }))
|
|
68
|
-
.handler((event, context) => {
|
|
69
|
-
return 'connected'
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const disconnectHandler = middy()
|
|
73
|
-
.use(validatorMiddleware({eventSchema: {...} }))
|
|
74
|
-
.handler((event, context) => {
|
|
75
|
-
return 'disconnected'
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
handler = middy()
|
|
79
|
-
.use(wsResponseMiddleware())
|
|
80
|
-
.handler(wsRouterHandler([
|
|
81
|
-
{
|
|
82
|
-
routeKey: '$connect',
|
|
83
|
-
handler: connectHandler
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
routeKey: '$disconnect',
|
|
87
|
-
handler: disconnectHandler
|
|
88
|
-
}
|
|
89
|
-
]))
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
module.exports = { handler }
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
## Middy documentation and examples
|
|
97
|
-
|
|
98
|
-
For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
## Contributing
|
|
102
|
-
|
|
103
|
-
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).
|
|
104
|
-
|
|
105
|
-
|
|
106
39
|
## License
|
|
107
40
|
|
|
108
41
|
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/ws-router",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "WebSocket 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": "4.0.
|
|
65
|
+
"@middy/util": "4.0.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@middy/core": "4.0.
|
|
68
|
+
"@middy/core": "4.0.1",
|
|
69
69
|
"@types/aws-lambda": "^8.10.100"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "c5ece2bfbb0d607dcdea5685bf194a6cc19acc8d"
|
|
72
72
|
}
|