Example of scalable dockerized backend using redis, socket.io, mongodb, nginx and including e2e tests.
- Socket connection requires authentication with JWT
- Connection status notification is forwarded to all friends of the user.
- Sent messages are forwarded to all friends of the user.
- Messages sent by the user's friends while the user is offline are forwarded when the user is online.
- Application can run on multiple servers
If you wish, you can use the erenkurnaz/websocket-example-web project written in Next.js to test the features with the user interface.
| Event | message | username | createdAt |
|---|---|---|---|
| message | string | string | Date |
| connected | string | string | Date |
| disconnected | string | string | Date |
| unseen_messages | string | string | Date |
# run the docker-compose file
$ docker-compose up -dAfter docker-compose initialized
- MongoDb runs on 27017:27017
- Seed data will be imported
- Nginx runs on 3000:80
- Apps runs as server-1, server-2
- Redis runs on 6379
After all, API runs on localhost:3000
| User | Password(decoded) | Name | Surname | Friends | |
|---|---|---|---|---|---|
| #1 | obi@mail.com | 123456 | Obivan | Kenobi | #2 - #3 |
| #2 | han@mail.com | 123456 | Han | Solo | #1 |
| #3 | anakin@mail.com | 123456 | Anakin | Skywalker | #1 |
# Install dependencies
$ yarn
# e2e tests
$ yarn test:e2eBefore you test the application make sure docker is up!
- auth.e2e-spec.ts
- check token sign and verify
- check login
- user.e2e-spec.ts
- check user create
- check add user to friends
- messages-gateway.e2e-spec.ts
- check unauthorized access
- check access with invalid token
- should sockets init successfully
- check message receive to friends
- check disconnected/connected notifications
- check receive unseen messages when connected

