I have this code here -
const wss = new SocketServer({ express() });
wss.on('connection', ws => {
console.log('Client connected');
ws.on('message', msg => {
console.log('received: %s', msg);
});
ws.on('close', () => console.log('Client disconnected'));
});
Now there are some problems, A D-Dos attack can crash my server.
Is there a way to check a token or something before allowing a stranger to connect to the websocket? Also the socket will be on another domain so cookies won't work.
Or is there a way to disconnect a user if he has not sent the authentication token after connecting.
If it were running and allowing everyone to connect indefinitely, then that's a security risk. Server can be brought down easily.