{"id":20875898,"url":"https://github.com/saqqdy/egg-http-proxy-plus","last_synced_at":"2025-05-12T15:31:53.918Z","repository":{"id":57220510,"uuid":"317112605","full_name":"saqqdy/egg-http-proxy-plus","owner":"saqqdy","description":"基于最新的http-proxy-middleware开发的更加智能的的egg代理中间件，解决了代理文件上传接口的问题","archived":false,"fork":false,"pushed_at":"2023-05-19T05:23:27.000Z","size":449,"stargazers_count":15,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-31T17:14:03.202Z","etag":null,"topics":["egg","egg-plugin","egg-proxy","file-upload","http-proxy","proxy","proxy-plus","rawbody","rawdata"],"latest_commit_sha":null,"homepage":"","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/saqqdy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["saqqdy"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-11-30T04:40:54.000Z","updated_at":"2024-07-02T04:25:44.000Z","dependencies_parsed_at":"2022-08-28T23:23:24.791Z","dependency_job_id":null,"html_url":"https://github.com/saqqdy/egg-http-proxy-plus","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-http-proxy-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-http-proxy-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-http-proxy-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saqqdy%2Fegg-http-proxy-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saqqdy","download_url":"https://codeload.github.com/saqqdy/egg-http-proxy-plus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225141027,"owners_count":17427206,"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":["egg","egg-plugin","egg-proxy","file-upload","http-proxy","proxy","proxy-plus","rawbody","rawdata"],"created_at":"2024-11-18T06:49:01.559Z","updated_at":"2024-11-18T06:49:02.003Z","avatar_url":"https://github.com/saqqdy.png","language":"JavaScript","funding_links":["https://github.com/sponsors/saqqdy"],"categories":[],"sub_categories":[],"readme":"\u003cdiv style=\"text-align: center;\" align=\"center\"\u003e\n\n# egg-http-proxy-plus\n\n\u003c/div\u003e\n\n\u003cdiv style=\"text-align: center;\" align=\"center\"\u003e\n\n支持转发文件上传接口，支持自定义匹配方法，ctx 透传\n\n\u003c/div\u003e\n\n\u003cdiv style=\"text-align: center;\" align=\"center\"\u003e\n\n[![NPM version][npm-image]][npm-url]\n[![Codacy Badge][codacy-image]][codacy-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n[![License][license-image]][license-url]\n\n[![Sonar][sonar-image]][sonar-url]\n\n\u003c/div\u003e\n\nConfigure proxy middleware for egg. Use [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware).\n\n## Install\n\n```bash\n# use npm\n$ npm i egg-http-proxy-plus --save\n\n# use yarn\n$ yarn add egg-http-proxy-plus\n```\n\n## Usage\n\n```js\n// {app_root}/config/plugin.js\nexports.httpProxyPlus = {\n  enable: true,\n  package: 'egg-http-proxy-plus'\n}\n```\n\n## Configuration\n\n### Proxy `/api` requests to `http://www.example.org`\n\n```js\n// {app_root}/config/config.default.js\nexports.httpProxyPlus = {\n  '/api': 'http://www.example.org'\n}\n// or\nexports.httpProxyPlus = [\n  {\n    origin: '/api',\n    options: 'http://www.example.org'\n  }\n]\n```\n\n#### A request to `/api/users` will now proxy the request to `http://www.example.org/api/users`\n\nIf you don't want `/api` to be passed along, we need to rewrite the path:\n\n```js\n// {app_root}/config/config.default.js\nexports.httpProxyPlus = {\n  '/api': {\n    target: 'http://www.example.org',\n    pathRewrite: { '^/api': '' }\n  }\n}\n// or\nexports.httpProxyPlus = [\n  {\n    origin: '/api',\n    options: {\n      target: 'http://www.example.org',\n      pathRewrite: { '^/api': '' }\n      // ...\n    }\n  }\n]\n```\n\n#### custom matching\n\nFor full control you can provide a custom function to determine which requests should be proxied or not.\n\n```js\n// {app_root}/config/config.default.js\nexports.httpProxyPlus = [\n  {\n    origin(pathname, req) {\n      return pathname.match('^/api') \u0026\u0026 req.method === 'GET'\n    },\n    options: {}\n  }\n]\n```\n\n#### http-proxy events\n\nPay attention to the fourth parameter, the plug-in transparently transmits the ctx context\n\n```js\n// {app_root}/config/config.default.js\nexports.httpProxyPlus = {\n  '/api': {\n    target: 'http://www.example.org',\n    onProxyReq(proxyReq, req, res, ctx) {\n      if (req.method.toLowerCase() === 'post') {\n        const token = ctx.cookies.get('access_token')\n        token \u0026\u0026 proxyReq.setHeader('authorization', token)\n      }\n    }\n  }\n}\n```\n\nFor more advanced usages, checkout [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware#options) options documentation.\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/saqqdy/egg-http-proxy-plus/issues).\n\n## License\n\n[MIT](LICENSE)\n\n\n[npm-image]: https://img.shields.io/npm/v/egg-http-proxy-plus.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-http-proxy-plus\n[codacy-image]: https://app.codacy.com/project/badge/Grade/f70d4880e4ad4f40aa970eb9ee9d0696\n[codacy-url]: https://www.codacy.com/gh/saqqdy/egg-http-proxy-plus/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=saqqdy/egg-http-proxy-plus\u0026utm_campaign=Badge_Grade\n[codecov-image]: https://img.shields.io/codecov/c/github/saqqdy/egg-http-proxy-plus.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/saqqdy/egg-http-proxy-plus?branch=master\n[download-image]: https://img.shields.io/npm/dm/egg-http-proxy-plus.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-http-proxy-plus\n[license-image]: https://img.shields.io/badge/License-MIT-blue.svg\n[license-url]: LICENSE\n[sonar-image]: https://sonarcloud.io/api/project_badges/quality_gate?project=saqqdy_egg-http-proxy-plus\n[sonar-url]: https://sonarcloud.io/dashboard?id=saqqdy_egg-http-proxy-plus\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaqqdy%2Fegg-http-proxy-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaqqdy%2Fegg-http-proxy-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaqqdy%2Fegg-http-proxy-plus/lists"}