{"id":13411325,"url":"https://github.com/fastify/fast-proxy","last_synced_at":"2025-03-14T17:30:31.061Z","repository":{"id":38018358,"uuid":"190131234","full_name":"fastify/fast-proxy","owner":"fastify","description":"Node.js framework agnostic library that enables you to forward an http request to another HTTP server. Supported protocols: HTTP, HTTPS, HTTP2","archived":true,"fork":false,"pushed_at":"2024-01-29T20:24:24.000Z","size":275,"stargazers_count":162,"open_issues_count":12,"forks_count":30,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-09-28T11:20:58.732Z","etag":null,"topics":["api","fastify-library","gateway","http","javascript","js","nodejs","proxy","rest","server"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fast-proxy","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"fastify","open_collective":"fastify"}},"created_at":"2019-06-04T04:53:21.000Z","updated_at":"2024-08-12T19:11:03.000Z","dependencies_parsed_at":"2023-02-06T07:16:42.521Z","dependency_job_id":"a0900e8f-0d6f-4ca0-a9de-b72041fc2b8f","html_url":"https://github.com/fastify/fast-proxy","commit_stats":{"total_commits":238,"total_committers":24,"mean_commits":9.916666666666666,"dds":0.5630252100840336,"last_synced_commit":"7692b35112a6b866a957ecd2344e696a1506ad09"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffast-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffast-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffast-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffast-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastify","download_url":"https://codeload.github.com/fastify/fast-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243606959,"owners_count":20318314,"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":["api","fastify-library","gateway","http","javascript","js","nodejs","proxy","rest","server"],"created_at":"2024-07-30T20:01:12.925Z","updated_at":"2025-03-14T17:30:30.762Z","avatar_url":"https://github.com/fastify.png","language":"JavaScript","readme":"# fast-proxy\n![CI](https://github.com/fastify/fast-proxy/workflows/CI/badge.svg)\n[![NPM version](https://img.shields.io/npm/v/fast-proxy.svg?style=flat)](https://www.npmjs.com/package/fast-proxy)  \n\nNode.js framework agnostic library that enables you to forward an http request to another HTTP server. \nSupported protocols: HTTP, HTTPS, HTTP2\n\n\u003e This library was initially forked from `fastify-reply-from`: https://github.com/fastify/fastify-reply-from\n\n`fast-proxy` powers: https://www.npmjs.com/package/fast-gateway 🚀 \n## Install\n```\nnpm i fast-proxy\n```\n\n## Usage\nThe following examples describe how to use `fast-proxy` with `restana`:\n\nGateway:\n```js\nconst { proxy, close } = require('fast-proxy')({\n  base: 'http://127.0.0.1:3000'\n  // options\n})\nconst gateway = require('restana')()\n\ngateway.all('/service/*', function (req, res) {\n  proxy(req, res, req.url, {})\n})\n\ngateway.start(8080)\n```\n\nRemote service:\n```js\nconst service = require('restana')()\nservice.get('/service/hi', (req, res) =\u003e res.send('Hello World!'))\n\nservice.start(3000)\n```\n\nUsing imports:\n```ts\nimport fastProxy from 'fast-proxy'\n\nconst { proxy, close } = fastProxy({\n  base: 'http://127.0.0.1:3000'\n})\n```\n\n## Benchmarks\nPlease see: https://github.com/jkyberneees/nodejs-proxy-benchmarks\n\n## API\n\n### Options\n#### `base`\nSet the base URL for all the forwarded requests. Will be required if `http2` is set to `true`\nNote that _path will be discarded_.\n\n#### queryString\nSet the query string parser and stringifier. By default `fast-proxy` uses the\n[fast-querystring](https://npmjs.com/package/fast-querystring) module. Configuration can be changed like so:\n\n```js\n{\n  base: 'http://localhost:3001/',\n  queryString: {\n    parse: (value) =\u003e qs.parse(value),\n    stringify: (value) =\u003e qs.stringify(value),\n  }\n}\n```\n\n#### http2\nSet to `true` if target server is `http2` enabled.\n\n#### undici\nSet to `true` to use [undici](https://github.com/mcollina/undici)\ninstead of `require('node:http')`. Enabling this flag should guarantee\n20-50% more throughput.\n\nThis flag could controls the settings of the undici client, like so:\n\n```js\n...\n  base: 'http://localhost:3001/',\n  undici: {\n    connections: 100,\n    pipelining: 10\n  }\n...\n```\n\u003e See undici demo at: `demos/gateway-undici.js`\n\n#### cacheURLs\nThe number of parsed URLs that will be cached. Default: 100.\n\u003e Use value = `0` to disable the caching mechanism\n\n#### requests.http and requests.https\nAllows to optionally overwrite the internal `http` and `https` client agents implementation. Defaults: [`http`](https://nodejs.org/api/http.html#http_http) and [`https`](https://nodejs.org/api/https.html#https_https).\n\nFor example, this could be used to add support for following redirects, like so:\n\n```js\n...\n  requests: {\n    http: require('follow-redirects/http'),\n    https: require('follow-redirects/https')\n  }\n...\n```\n\u003e If using `undici` or `http2` this settings are ignored!\n\n#### keepAliveMsecs\nDefaults to 1 minute, passed down to [`http.Agent`][http-agent] and\n[`https.Agent`][https-agent] instances.\n\n#### maxSockets\nDefaults to 2048 sockets, passed down to [`http.Agent`][http-agent] and\n[`https.Agent`][https-agent] instances.\n\n#### rejectUnauthorized\nDefaults to `true`, passed down to [`https.Agent`][https-agent] instances.\nThis needs to be set to `false` to reply from https servers with\nself-signed certificates.\n\n#### Extended configurations\nOther supported configurations in https://nodejs.org/api/http.html#http_new_agent_options can also be part of the `opts` object.\n\n### close\nOptional _\"on `close` resource release\"_ strategy. You can link this to your application shutdown hook as an example.\n\n### proxy(originReq, originRes, source, [opts])\nEnables you to forward an http request to another HTTP server.\n```js\nproxy(\n  originReq,                          // http.IncomingMessage \n  originRes,                          // http.ServerResponse\n  req.url,                            // String -\u003e remote URL + path or path if base was set\n  {}                                  // Options described below\n)\n```\n#### opts\n\n##### base\nOptionally indicates the base URL for the current request proxy. When used, the global `base` config is overwriten.  \n\u003e This configuration value is ignored when using HTTP2.\n\n##### onResponse(req, res, stream)\nCalled when an http response is received from the source.\nThe default behavior is `pump(stream, res)`, which will be disabled if the\noption is specified.\n\n##### rewriteRequestHeaders(req, headers)\nCalled to rewrite the headers of the request, before them being sent to the downstream server. \nIt must return the new headers object.\n\n##### rewriteHeaders(headers)\nCalled to rewrite the headers of the response, before them being copied\nover to the outer response.\nIt must return the new headers object.\n\n##### request\nExtended options supported by `http[s].request` method (https://nodejs.org/api/http.html#http_http_request_options_callback)\nThe following options are dynamically assigned: `method, port, path, hostname, headers, agent`.  \n\n\u003e `http2` options are limited to `timeout` only, while `undici` supports none.\n\n##### queryString\nReplaces the original querystring of the request with what is specified.\nThis will get passed to\n[`querystring.stringify`](https://nodejs.org/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options).\n\n## Related topics\n- http-agent: https://nodejs.org/api/http.html#http_new_agent_options\n- https-agent: https://nodejs.org/api/https.html#https_class_https_agent\n\n## Contributions \nSpecial thanks to `fastify-reply-from` developers for creating a production ready library from where we could initially fork.\n\n## License\nMIT\n","funding_links":["https://github.com/sponsors/fastify","https://opencollective.com/fastify"],"categories":["Repository","JavaScript","Web Development"],"sub_categories":["HTTP","Javascript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffast-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastify%2Ffast-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffast-proxy/lists"}