Skip to content

erenkurnaz/websocket-example

Repository files navigation

Nest Logo

Nestjs Scalable Websocket Example with e2e Testing

Example of scalable dockerized backend using redis, socket.io, mongodb, nginx and including e2e tests.

Nest Logo

Features

  • 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 Types

Event message username createdAt
message string string Date
connected string string Date
disconnected string string Date
unseen_messages string string Date

Installation and Running the app

# run the docker-compose file
$ docker-compose up -d

After docker-compose initialized

  1. MongoDb runs on 27017:27017
  2. Seed data will be imported
  3. Nginx runs on 3000:80
  4. Apps runs as server-1, server-2
  5. Redis runs on 6379

After all, API runs on localhost:3000

Seeded Data

User Email 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

Flowcharts

Nest Logo

Test

# Install dependencies 
$ yarn

# e2e tests
$ yarn test:e2e

Before 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors