ryo-ma / deno-websocket

🦕 A simple WebSocket library like ws of node.js library for deno
https://deno.land/x/websocket
MIT License
152 stars 17 forks source link

Allow forwarding IPs when running server behind proxy #14

Closed asjur closed 3 years ago

asjur commented 3 years ago

This came from one of my needs developing a websocket server using this library's implementation. I proxy the Deno application behind Nginx, which causes the IP sent by this library to be the IP of the Nginx proxy.

This change allows you to specify the header which you want to forward the real ip to the ip of the socket.

It's usage is as simple as this. const WSS = new WebSocketServer(5050, 'x-forwarded-for');

This will run a server on port 5050 where nginx sets the real IP to header 'x-forwarded-for'. This then replaces the IP of the proxy so when attempting to view the connection info of a socket, you will get the real IP instead of the nginx proxy IP.