0.0.2 • Published 5 years ago

koa-api-proxies v0.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

koa-api-proxies

koa2 http proxy middleware

### Support

post、get、put、delete 基本请求, 文件上传

### Use

npm install koa-api-proxies

ProxyConfig

参数类型说明
targetstring代理地址(domain+port)
pathstring(string array)代理匹配url,支持字符串数组,字符串
headersobject自定义header相关,如cookie, ua
beforeSendfunciton请求前处理,参数ctx, options完整转发配置

Example

    const Koa = require('koa')
    const app = new Koa()
    const proxy = require('koa-api-proxies')
    /**
     * use config single
     * @type {[type]}
     */
    /**
     * use config multi
     * @type {[type]}
     */
    app.use(proxy([{
      target: 'http://www.google.com',
      path: ['/dist', '/dist2'],
    }, {
      target: 'http://www.yahoo.com',
      path: '/t',
      beforeSend:(ctx, options) => {
      }
    }]))