The Socket.IO server application will expect the users to be logged-in in order for them to be able to connect to the /home namespace. Using socket middleware, we will also restrict access to /home namespace to a certain user:
- Create a new file named middleware-server.js
- Include the Socket.IO library and initialize a new HTTP server:
const http = require('http') const fs = require('fs') const path = require('path') const io = require('socket.io')() const app = http.createServer((req, res) => { if (req.url === '/') { fs.readFile( path.resolve(__dirname, 'middleware-cli.html'), (err, data) => { if (err) { res.writeHead(500) return void res.end() } res.writeHead(200) res.end(data) } ) } else { res.writeHead(403) res.end() ...