{"id":19240896,"url":"https://github.com/binocarlos/hyperprox","last_synced_at":"2025-07-12T21:41:33.709Z","repository":{"id":19454639,"uuid":"22698975","full_name":"binocarlos/hyperprox","owner":"binocarlos","description":"simple HTTP proxy based on hyperquest","archived":false,"fork":false,"pushed_at":"2015-12-23T17:39:07.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-13T02:04:25.802Z","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/binocarlos.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":"2014-08-06T21:35:54.000Z","updated_at":"2014-10-06T10:27:12.000Z","dependencies_parsed_at":"2022-08-23T22:40:32.719Z","dependency_job_id":null,"html_url":"https://github.com/binocarlos/hyperprox","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/binocarlos%2Fhyperprox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fhyperprox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fhyperprox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fhyperprox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binocarlos","download_url":"https://codeload.github.com/binocarlos/hyperprox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240326592,"owners_count":19783877,"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-09T17:09:24.565Z","updated_at":"2025-02-23T14:27:17.419Z","avatar_url":"https://github.com/binocarlos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"hyperprox\n---------\n\nsimple HTTP proxy based on [hyperquest](https://github.com/substack/hyperquest)\n\n## install\n\n```\n$ npm install hyperprox\n```\n\n## usage\nCreate a proxy by passing a function that will resolve what backend to use to the given request\n\n```js\nvar http = require(\"http\")\nvar hyperprox = require('hyperprox')\n\nvar backends = hyperprox(function(req){\n  // calculate the proxy destination\n  var port = req.url=='/a' ? 8081 : 8082\n  return 'http://127.0.0.1:' + port\n})\n\n// the front facing web server\nvar router = http.createServer(backends.handler())\n\nbackends.on('request', function(req, res){\n\t\n})\n\nbackends.on('route', function(req, address){\n\t\n})\n\nvar serverA = http.createServer(function(req, res){\n  res.end('serverA')\n})\n\nvar serverB = http.createServer(function(req, res){\n  res.end('serverB')\n})\n\nrouter.listen(8080)\nserverA.listen(8081)\nserverB.listen(8082)\n```\n\n## streams\n\nWe can generate a duplex stream for a request that will auto-route - this lets us filter the input and output:\n\n```js\nvar through = require('through2')\nvar backends = hyperprox(function(req){\n  var port = req.url=='/a' ? 8081 : 8082\n  return 'http://127.0.0.1:' + port\n})\n\nvar router = http.createServer(function(req, res){\n\tvar proxy = backends.duplex(req, res)\n\n\t// filter the request body\n\tvar inputFilter = through(function(chunk, enc, next){\n\t\tthis.push(chunk.toString() + 'a')\n\t\tnext()\n\t})\n\n\t// filter the response body\n\tvar outputFilter = through(function(chunk, enc, next){\n\t\tthis.push(chunk.toUpperCase())\n\t\tnext()\n\t})\n\n\t// REQUEST -\u003e INPUT FILTER -\u003e PROXY -\u003e OUTPUT FILTER -\u003e RESPONSE\n\treq.pipe(inputFilter).pipe(proxy).pipe(outputFilter).pipe(res)\n})\n```\n\n## async routing\n\nYour routing function can be asynchronous - this means you can ask an external service for routing data:\n\nIf you define `next` in the parameters then it will be treated as an async router.\n\n```js\nvar proxy = hyperprox(function(req, next){\n\n\tloadRoute(req.url, function(err, address){\n\t\tnext(err, address)\n\t})\n\t\n})\n```\n\n## api\n\n#### `hyperprox.proxy(req, res, address, [input, output])`\n\nA direct proxy function that will send req via address to res\n\nInput and output are optional override streams to replace req and res\n\n#### `var backends = hyperprox(function(req, next){})`\n\nCreate a new proxy by passing a function that will resolve the backend address and pass it to the 'next' function\n\n#### `backends.handler()`\n\nReturn a `function(req,res){}` that will proxy requests using the routing function\n\n#### `backends.proxy(req, res, address, [input, output])`\n\nA direct proxy that will pipe req via address and to res\n\nIf input and output are provided - they will be used as the streams rather than req and res\n\n#### `backends.resolve(req, done)`\n\nThe resolving function that goes via the user supplied function\n\n#### `backends.duplex(req, res)`\n\nReturn a duplex stream going through the backend - you can write it to the original request / response how you want:\n\n```js\nvar duplex = backends.duplex(req, res)\nreq.pipe(duplex).pipe(res)\n```\n\nIf there is an error with routing the response will be set to 500 and the backend skipped\n\n## events\n\n#### `backends.on('request', function(req, res){})`\n\nwhen a request arrives at the proxy\n\n#### `backends.on('route', function(req, address){})`\n\nOnce a routing decision has been made\n\n## license\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinocarlos%2Fhyperprox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinocarlos%2Fhyperprox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinocarlos%2Fhyperprox/lists"}