https://github.com/tashuo/nest-websocket
nest websocket example
https://github.com/tashuo/nest-websocket
jwt nest nestjs nodejs socket-io typeorm websocket
Last synced: 4 months ago
JSON representation
nest websocket example
- Host: GitHub
- URL: https://github.com/tashuo/nest-websocket
- Owner: tashuo
- Created: 2023-04-13T12:37:51.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-14T08:39:42.000Z (almost 3 years ago)
- Last Synced: 2025-04-04T20:36:06.866Z (10 months ago)
- Topics: jwt, nest, nestjs, nodejs, socket-io, typeorm, websocket
- Language: TypeScript
- Homepage:
- Size: 95.7 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
A progressive Node.js framework for building efficient and scalable server-side applications.
## Description
A nest websocket example with auth.
实现了websocket连接鉴权、心跳保活、私聊和系统主动推送通知等逻辑
## Installation
```bash
# install
$ pnpm up -latest
# .env
$ cp .env.example .env # modify the config with yours
# run migration
$ pnpm typeorm:run-migrations
```
## Running the app
```bash
# development
$ pnpm start
# watch mode
$ pnpm start:dev
```
## Test
### login to get jwt
*the test users Jim and John are auto generated on nest start, look at [OnApplicationBootstrap](https://github.com/tashuo/nest-websocket/blob/master/src/modules/user/user.module.ts)*
```bash
$ curl -X POST \
'127.0.0.1:3000/user/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "Jim",
"password": "123456"
}'
$ curl -X POST \
'127.0.0.1:3000/user/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "John",
"password": "123456"
}'
```
### test with Postman
#### connect to ws server with jwt token
[](https://imgloc.com/i/ixBr6Q)
#### add chat event listener
[](https://imgloc.com/i/ixBGld)
#### send message directly with ws
[](https://imgloc.com/i/ixBYc5)
[](https://imgloc.com/i/ixXVGH)
#### send message with http api
[](https://imgloc.com/i/ixXO7d)
[](https://imgloc.com/i/ixXev5)
### test heartbeat
#### normal
[](https://imgloc.com/i/ixgprJ)
#### timeout
[](https://imgloc.com/i/ixgdDz)
## License
Nest is [MIT licensed](LICENSE).