scalable-nodejs-socketio-redis-nginx-example
scalable-nodejs-socketio-redis-nginx-example copied to clipboard
Simple example of scalable nodejs websocket server
Scalable socketio server
Shows a list of IP addresses viewing the page
Application launched with docker: node server with redis server as a message broker for scaling
and nginx server as a balancer and web server for static client files (index.html and index.js)
Installation
git clonethis repo- Make sure you use latest
dockeranddocker-compose - Run
yarn buildfromclientdirectory to createdist/index.jsbundle - Run
docker-compose up. It buildsweb,redisandsocket-servercontainers for you. Rundocker-compose buildif you want to rebuild containers - Site available on
0.0.0.0:80on Unix-like systems (checkifconfigto find correct IP if not)
Development
Client uses Webpack to create bundle dist/index.js.
If something changed in client/src directory, yarn build should be launched to update index.js bundle
Automated Test
- Unit tests launch
yarn test-unit - Functional tests must be launched in docker env like
docker exec currentlyviewingapp_socket-server_1 yarn test-func
Manual Test
!!!NOTE!!! In purpose of testing on one machine, websocket server doesn't use real IPs, but number which changed every 10 seconds.
When user opens a tab in browser, number N assigned to this tab via socket connection.
When user opens the second tab in browser, application assigns the same number N or the new number M.
IF the second tab assigned with number N and user closes the first tab, it's "IP-number" still in the list, because there is at least one tab. It allows to see how would it work if user opens many tabs from the same and different computers.
Uncomment server/src/index.js:15 if you wish to see real IP addresses (requires to restart docker container)
TODOs
- add deploy script to launch
yarn buildbefore docker containers start. Ignore client index.js bundle from get repo