{"id":27942427,"url":"https://github.com/vagusX/koa-proxies","last_synced_at":"2025-05-07T11:33:44.304Z","repository":{"id":38403969,"uuid":"76923689","full_name":"vagusX/koa-proxies","owner":"vagusX","description":"a koa@2.x+ proxy middleware","archived":false,"fork":false,"pushed_at":"2024-12-02T03:05:19.000Z","size":81,"stargazers_count":161,"open_issues_count":11,"forks_count":45,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-28T21:08:13.096Z","etag":null,"topics":["koa","koa-middleware","koa-proxies","koa2","node-http-proxy","proxy"],"latest_commit_sha":null,"homepage":"https://vagusx.github.io/koa-proxies/","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/vagusX.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","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}},"created_at":"2016-12-20T04:42:50.000Z","updated_at":"2024-08-23T22:24:08.000Z","dependencies_parsed_at":"2024-06-18T12:40:24.610Z","dependency_job_id":"0be97508-6936-4732-a089-9e1038fe5ee0","html_url":"https://github.com/vagusX/koa-proxies","commit_stats":{"total_commits":73,"total_committers":16,"mean_commits":4.5625,"dds":0.4383561643835616,"last_synced_commit":"5653d31da2f4116b847e074d46e055f8b09d53b2"},"previous_names":[],"tags_count":21,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vagusX%2Fkoa-proxies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vagusX%2Fkoa-proxies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vagusX%2Fkoa-proxies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vagusX%2Fkoa-proxies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vagusX","download_url":"https://codeload.github.com/vagusX/koa-proxies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252299553,"owners_count":21725722,"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":["koa","koa-middleware","koa-proxies","koa2","node-http-proxy","proxy"],"created_at":"2025-05-07T11:33:39.932Z","updated_at":"2025-05-07T11:33:44.273Z","avatar_url":"https://github.com/vagusX.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Koa Proxies\n\n![NPM](https://img.shields.io/npm/v/koa-proxies.svg)\n\n[![Node.js CI](https://github.com/vagusX/koa-proxies/actions/workflows/node.js.yml/badge.svg)](https://github.com/vagusX/koa-proxies/actions/workflows/node.js.yml)\n[![Coverage](https://img.shields.io/codecov/c/github/vagusX/koa-proxies.svg)](https://codecov.io/gh/vagusX/koa-proxies)\n[![NPM Downloads](https://img.shields.io/npm/dm/koa-proxies.svg)](https://www.npmjs.com/package/koa-proxies)\n[![Greenkeeper badge](https://badges.greenkeeper.io/vagusX/koa-proxies.svg)](https://greenkeeper.io/)\n\n\u003e [Koa@2.x/next](https://github.com/koajs/koa) middlware for http proxy\n\nPowered by [`http-proxy`](https://github.com/nodejitsu/node-http-proxy).\n\n## Installation\n\n```bash\n$ npm install koa-proxies --save\n```\n\n## Options\n\n### http-proxy events\n\n```js\noptions.events = {\n  error (err, req, res) { },\n  proxyReq (proxyReq, req, res) { },\n  proxyRes (proxyRes, req, res) { }\n}\n```\n\n### log option\n```js\n// enable log\noptions.logs = true; // or false\n\n// custom log function\noptions.logs = (ctx, target) {\n  console.log('%s - %s %s proxy to -\u003e %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, new URL(ctx.req.url, target))\n}\n```\n\n## Usage\n\n```js\n// dependencies\nconst Koa = require('koa')\nconst proxy = require('koa-proxies')\nconst httpsProxyAgent = require('https-proxy-agent')\n\nconst app = new Koa()\n\n// middleware\napp.use(proxy('/octocat', {\n  target: 'https://api.github.com/users/',\n  changeOrigin: true,\n  agent: new httpsProxyAgent('http://1.2.3.4:88'), // if you need or just delete this line\n  rewrite: path =\u003e path.replace(/^\\/octocat(\\/|\\/\\w+)?$/, '/vagusx'),\n  logs: true\n}))\n```\nThe 2nd parameter `options` can be a function. It will be called with the path matching result (see [path-match](https://www.npmjs.com/package/path-match) for details) and Koa `ctx` object. You can leverage this feature to dynamically set proxy. Here is an example:\n\n```js\n// dependencies\nconst Koa = require('koa')\nconst proxy = require('koa-proxies')\n\nconst app = new Koa()\n\n// middleware\napp.use(proxy('/octocat/:name', (params, ctx) =\u003e {\n  return {\n    target: 'https://api.github.com/',\n    changeOrigin: true,\n    rewrite: () =\u003e `/users/${params.name}`,\n    logs: true\n  }})\n)\n```\nMoreover, if the `options` function return `false`, then the proxy will be bypassed. This allows the middleware to bail out even if path matching succeeds, which could be helpful if you need complex logic to determine whether to proxy or not.\n\n\n### Attention\n\nPlease make sure that `koa-proxies` is in front of `koa-bodyparser` to avoid this [issue 55](https://github.com/vagusX/koa-proxies/issues/55)\n\n```js\nconst Koa = require('koa')\nconst app = new Koa()\nconst proxy = require('koa-proxies')\nconst bodyParser = require('koa-bodyparser')\n\napp.use(proxy('/user', {\n  target: 'http://example.com',\n  changeOrigin: true\n}))\n\napp.use(bodyParser())\n```\n\n[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FvagusX%2Fkoa-proxies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FvagusX%2Fkoa-proxies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FvagusX%2Fkoa-proxies/lists"}