https://github.com/eugenecn/koa-server-http-proxy
A koa-http-proxy-middleware
https://github.com/eugenecn/koa-server-http-proxy
koa koa-http-proxy koa-http-proxy-middleware koa-proxy
Last synced: 19 days ago
JSON representation
A koa-http-proxy-middleware
- Host: GitHub
- URL: https://github.com/eugenecn/koa-server-http-proxy
- Owner: eugeneCN
- Created: 2018-08-06T11:26:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-07T05:10:45.000Z (over 6 years ago)
- Last Synced: 2024-03-23T14:02:34.584Z (about 1 year ago)
- Topics: koa, koa-http-proxy, koa-http-proxy-middleware, koa-proxy
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 37
- Watchers: 0
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-server-http-proxy
A koa2 http-proxy-middleware.
## Installation
```bash
$ npm install koa-server-http-proxy --save
```## Example
```js
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
```js
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](https://github.com/chimurai/http-proxy-middleware#options) for full list of
accepted options.## License
MIT