{"_id":"koa-proxies@0.12.6","bugs":{"url":"https://github.com/vagusX/koa-proxies/issues"},"dist":{"shasum":"b44a57537097706c3387323ffcc28e4a31b17e5b","tarball":"http://registry-npm.ywwl.com/koa-proxies/download/koa-proxies-0.12.6.tgz","fileCount":9,"integrity":"sha512-KXYKAnw2x7I6GrKNbxFpDnDuK0Ina/Lxn3IYn1I7/6hEFKONlKxcgNYm6JdzVQQWG3Wdje/IyaavvDGwmFzxNw==","signatures":[{"sig":"MEMCIEU4TGuUC8XPbGbQgM6Fw4MREYYggYe4gRvVzty3dcCXAh8C2V3KfIGUB7+JuKBS8Alal5Nhkmklnzs7U1d6accb","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICWXQ04o8bAPzpjRrifomzAU5x9fvueDIhMWCK20/MPnAiEAjaty2q3496WFmrGVc+P/b9r6RMsMI1WYIeg8Sr4+G6w="}],"unpackedSize":15937,"size":6359,"noattachment":false,"key":"/koa-proxies/-/koa-proxies-0.12.6.tgz"},"main":"index.js","name":"koa-proxies","husky":{"hooks":{"commit-msg":"commitlint -E HUSKY_GIT_PARAMS","pre-commit":"lint-staged"}},"author":{"name":"vagusX"},"gitHead":"b296cde123c1d3d1b0bc4d57e4505216ba4116ad","license":"MIT","scripts":{"ci":"npm run lint && npm test && npm run coverage","pub":"npm run version && npm publish","lint":"eslint index.js test/","test":"nyc mocha","version":"standard-version","coverage":"nyc report --reporter=lcov --reporter=html","test:types":"npm --prefix test/types test"},"typings":"index.d.ts","version":"0.12.6","_npmUser":{"name":"vagusx","email":"onlylae@sina.com"},"homepage":"https://github.com/vagusX/koa-proxies#readme","keywords":["koa","middleware","proxy","proxies"],"repository":{"url":"git+https://github.com/vagusX/koa-proxies.git","type":"git"},"_npmVersion":"11.5.1","description":"Http Proxy Middleware for Koa 2 and 3","directories":{},"lint-staged":{"*.js":"npm run lint"},"maintainers":[{"name":"vagusx","email":"onlylae@sina.com"}],"_nodeVersion":"24.7.0","dependencies":{"uuid":"^8.3.2","http-proxy":"^1.18.1","path-match":"^1.2.4"},"publishConfig":{"registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"devDependencies":{"koa":"^2.5.2","nyc":"^15.1.0","chai":"^4.1.2","husky":"^4.0.2","mocha":"^8.2.1","sinon":"^9.2.1","eslint":"^6.5.1","lint-staged":"^10.5.1","@commitlint/cli":"^8.2.0","standard-version":"^9.3.2","eslint-plugin-node":"^11.0.0","eslint-plugin-mocha":"^6.1.1","eslint-plugin-import":"^2.18.2","eslint-plugin-promise":"^4.2.1","eslint-config-standard":"^14.1.0","eslint-plugin-standard":"^4.0.1","@commitlint/config-conventional":"^8.2.0"},"peerDependencies":{"koa":">=2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/koa-proxies_0.12.6_1791446703338_0.2347714083108492"},"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[![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> [Koa 2 and 3](https://github.com/koajs/koa) middleware for HTTP proxy\n\nKoa 3 requires Node.js 18 or newer. Koa 2 remains supported.\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 -> %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 => 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) => {\n  return {\n    target: 'https://api.github.com/',\n    changeOrigin: true,\n    rewrite: () => `/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### TypeScript\n\nPass your application's state and context types to type the options and logging\ncallbacks, as well as the returned middleware:\n\n```ts\nimport proxy = require('koa-proxies')\n\nproxy<{ userId: string }, { tenant: string }>('/api', (params, ctx) => ({\n  target: `https://${ctx.tenant}.example.com`,\n  logs: ctx => console.log(ctx.state.userId)\n}))\n```\n\nThese types describe fields provided by your application; they do not create or\nvalidate those fields at runtime. Existing calls without type arguments and\noptions callbacks returning `false` remain supported.\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## Development checks\n\n```sh\nnpm ci\nnpm run ci\n```\n\nThis uses the committed lockfile for a reproducible baseline. CI also runs the\nsame lint, runtime tests and coverage checks with freshly resolved dependencies\non every Node version in the matrix. To reproduce that check, use a fresh\ncheckout with no `node_modules` and run:\n\n```sh\nnpm install --package-lock=false\nnpm run ci\n```\n\nThe second install ignores the repository lockfile and resolves the ranges in\n`package.json`. Failures in either installation mode fail CI. A library's\nlockfile does not constrain its consumers' dependency versions: these checks\ncover the locked baseline and a fresh resolution, not every possible downstream\ndependency combination.\n\nRuntime tests use local HTTP fixtures and run on Node 12, 14, 16, 18, 20, 22 and\n24 in CI. Older versions remain compatibility checks, not security-support\nrecommendations. Coverage is saved as a `coverage` artifact in the\n[CI run](https://github.com/vagusX/koa-proxies/actions/workflows/node.js.yml).\n\nKoa 3.0.1 runtime tests, Koa 3 type declaration checks and the TypeScript sample\ncompile check also run on Node 18 and 24.\n\nType declaration checks use a separate modern toolchain; see\n[test/types](test/types/README.md) for the locked setup and commands.\n\n[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n","publish_time":1791446703472,"_cnpm_publish_time":1791446703472,"dist-tags":{"latest":"0.12.6"}}