crossws 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -696,8 +696,13 @@ class NodePeer extends types.Peer {
696
696
  if (!socket) {
697
697
  return void 0;
698
698
  }
699
- const addr = socket.remoteFamily === "IPv6" ? `[${socket.remoteAddress}]` : socket.remoteAddress;
700
- return `${addr}:${socket.remotePort}`;
699
+ const headers = this.ctx.node.req.headers;
700
+ let addr = headers["x-forwarded-for"] || socket.remoteAddress || "??";
701
+ if (addr.includes(":")) {
702
+ addr = `[${addr}]`;
703
+ }
704
+ const port = headers["x-forwarded-port"] || socket.remotePort || "??";
705
+ return `${addr}:${port}`;
701
706
  }
702
707
  get url() {
703
708
  return this.ctx.node.req.url || "/";
@@ -688,8 +688,13 @@ class NodePeer extends Peer {
688
688
  if (!socket) {
689
689
  return void 0;
690
690
  }
691
- const addr = socket.remoteFamily === "IPv6" ? `[${socket.remoteAddress}]` : socket.remoteAddress;
692
- return `${addr}:${socket.remotePort}`;
691
+ const headers = this.ctx.node.req.headers;
692
+ let addr = headers["x-forwarded-for"] || socket.remoteAddress || "??";
693
+ if (addr.includes(":")) {
694
+ addr = `[${addr}]`;
695
+ }
696
+ const port = headers["x-forwarded-port"] || socket.remotePort || "??";
697
+ return `${addr}:${port}`;
693
698
  }
694
699
  get url() {
695
700
  return this.ctx.node.req.url || "/";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crossws",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Cross-platform WebSocket Servers for Node.js, Deno, Bun and Cloudflare Workers",
5
5
  "repository": "unjs/crossws",
6
6
  "license": "MIT",