koa-any-proxy
koa proxy http
Koa middlware for http proxy
Powered by http-proxy
Powered by url-pattern
install
$ npm install koa-any-proxy --save
rules
// ***source*** , ***target*** 参考[`url-pattern`](https://www.npmjs.com/package/url-pattern) 规则// ***options*** , 参考[`http-proxy`](https://github.com/nodejitsu/node-http-proxy) proxy.web(req,res,options)中的options // Rule (1) source : '/v:major(.:minor)/*' target : 'http://localhost:8080/cool' options: {}//详见文档[options](https://github.com/nodejitsu/node-http-proxy#options) events: //详见文档[events](https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events) {} {} {} {} {} {} // Rule (2) source:'/api/users/:ids/posts/:ids' target: 'http://localhost:8080/:ids/:ids' options:{} events:{} // Rule (3) source:'/api/users(/:id)' target: 'http://localhost:8080(/:id)' options:{} // Rule (4) source:'/api/users(/:id)' target: 'http://localhost:8080(/:id)' options:{} ...
options
{
}
usage
// dependenciesconst Koa = const proxy = const app = // middlewareapp
notes
请务必在初始化在koa中间件的第一顺位 , 避免不必要问题