{"id":18544732,"url":"https://github.com/131/socketwrap","last_synced_at":"2025-05-15T05:34:16.235Z","repository":{"id":57365597,"uuid":"380993970","full_name":"131/socketwrap","owner":"131","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-28T11:40:25.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-21T18:05:47.004Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/131.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-28T10:36:02.000Z","updated_at":"2021-11-16T11:19:53.000Z","dependencies_parsed_at":"2022-08-23T20:10:12.223Z","dependency_job_id":null,"html_url":"https://github.com/131/socketwrap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsocketwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsocketwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsocketwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsocketwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/131","download_url":"https://codeload.github.com/131/socketwrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254282777,"owners_count":22045129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T20:17:27.110Z","updated_at":"2025-05-15T05:34:16.208Z","avatar_url":"https://github.com/131.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Socketwrap\n\nAdd [PROXY protocol](http://haproxy.1wt.eu/download/1.5/doc/proxy-protocol.txt). v1 or v2 support to nodejs sockets. IPv4 and IPv6 protocols supported\n\n## History\n\nThis module is a fork of original [proxywrap](https://github.com/cusspvz/proxywrap) by [Josh Dague](https://github.com/daguej), [José Moreira\n](https://github.com/cusspvz) and [Short-io/proxywrap](https://github.com/Short-io/proxywrap). Those projects all relies on hooking/rewriting nodejs servers. This module implement a simplier async \"socket validation\" callback policy.\n\nThis module validate a newly opened nodejs socket, automatically parses the PROXY headers and resets `socket.remoteAddress` and `socket.remotePort` so that they have the correct values. Then trigger a simple callback\n\nThis module wraps node's various `Server` interfaces so that they are compatible with the \n\nThis module is especially useful if you need to get the client IP address when you're behind an AWS ELB in TCP mode.\n\n## Installing\n\n```bash\nnpm install --save socketwrap\n```\n\n## Usage\n\n```js\nconst net = require('net')\nvar {socketwrap, override}  = require('socketwrap');\n\nvar srv = new net.Server( async (socket) {\n\n  let {remoteAddress, remotePort} = await socketwrap(socket);\n  override(socket, {remoteAddress, remotePort}); //you might want to deal with that in another way\n\n  socket.pipe(somedest);\n  console.log(\"IP = %s:%d\", socket.remoteAddress, socket.remotePort);\n});\n\nsrv.listen( 80 )\n\n```\nThis also adds to all your sockets the properties:\n* `socket.clientAddress` - The IP Address that connected to your PROXY.\n* `socket.clientPort` - The Port used by who connected to your PROXY.\n* `socket.proxyAddress` - The IP Address exposed on Client \u003c-\u003e Proxy side.\n* `socket.proxyPort` - The Port exposed on Client \u003c-\u003e Proxy side. Usefull for detecting SSL on AWS ELB.\n* `socket.remoteAddress` [optional] - Same as `socket.clientAddress`, used for compability proposes.\n* `socket.remotePort` [optional] - Same as `socket.clientPort`, used for compability proposes.\n\n**Warning:** By default, *all* traffic to your proxied server MUST use the PROXY protocol.  If the first five bytes received aren't `PROXY`, the connection will be dropped.  Obviously, the node server accepting PROXY connections should not be exposed directly to the internet; only the proxy (whether ELB, HAProxy, or something else) should be able to connect to node.\n\n## API\n\n\n### `\u003cproxyInfo\u003e async socketwrap(socket)`\n\nParse a socket header for PROXY protocol support.\n\n\n\n## Contribute\n\nDo you have any idea to improve this module?\nFeel free to open an [Issue](https://github.com/131/socketwrap/issues/new) or a [Pull Request](https://github.com/131/socketwrap/pulls).\n\n\n## Credits\n* [131](https://github.com/131)\n* [Josh Dague](https://github.com/daguej) for creating original [proxywrap](https://github.com/daguej/node-proxywrap).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fsocketwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F131%2Fsocketwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fsocketwrap/lists"}