koa-server-http-proxy
A koa2 http-proxy-middleware.
Last updated 2 years ago by eugene_cn .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install koa-server-http-proxy 
SYNC missed versions from official npm registry.

koa-server-http-proxy

A koa2 http-proxy-middleware.

Installation

$ npm install koa-server-http-proxy --save

Example

const Koa = require('koa')

const app = new Koa()

const proxy = require('koa-server-http-proxy')

app.use(proxy('/api', {
  target: 'https://news-at.zhihu.com',
  pathRewrite: { '^/api': 'api/4/' },
  changeOrigin: true
}))

app.listen(3000)


Browser

http://127.0.0.1:3000/api/themes

Example2

const Koa = require('koa')

const app = new Koa()

const proxy = require('koa-server-http-proxy')

const proxyTable = {
  '/json': {
    target: 'http://jsonplaceholder.typicode.com',
    pathRewrite: { '^/json': '' },
    changeOrigin: true
  },
  '/api': {
    target: 'https://news-at.zhihu.com',
    pathRewrite: { '^/api': 'api/4/' },
    changeOrigin: true
  }
}

Object.keys(proxyTable).forEach((context) => {
  var options = proxyTable[context]
  app.use(proxy(context, options))
})

app.listen(3000)


Options

All options are passed to http-proxy-middleware, except that if options is passed as a string, it will normalized as options' target.

See http-proxy-middleware for full list of accepted options.

License

MIT

Current Tags

  • 0.1.0                                ...           latest (2 years ago)

1 Versions

  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 15
This Month 141
Last Day 15
Last Week 177
Last Month 867
Dependencies (2)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |