https://github.com/gera2ld/koa-proxypass
A proxy-pass server for koa
https://github.com/gera2ld/koa-proxypass
Last synced: about 1 year ago
JSON representation
A proxy-pass server for koa
- Host: GitHub
- URL: https://github.com/gera2ld/koa-proxypass
- Owner: gera2ld
- Created: 2016-02-03T01:39:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-18T10:33:52.000Z (over 10 years ago)
- Last Synced: 2025-02-16T14:57:56.431Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
koa-proxypass
===



A proxy-pass server for koa.
Installation
---
``` sh
$ npm install koa-proxypass
```
Usage
---
``` javascript
const koa = require('koa')
const proxy = require('koa-proxypass')
const app = koa()
app.use(proxy({
upstreams: [{
match: {
host: 'localhost',
},
children: [{
match: {
path: /^\/api\//,
},
target: 'http://gerald.top',
path: '',
}],
}]
}))
```
Document
---
There is one parameter `options` for `proxy`. `options` has attributes below:
* `upstreams`
an array of upstream rules, each rule may have attributes below:
* `match`: Object | Function (param *request*)
The object will be tested for each key-value pairs, and return true if all matched. Each value can be an `RegExp` or `Function (param *responding-value*)` for smart test or `Any` for exact match.
The function will have the request object with `method`, `path`, `header` attributes as the only parameter.
* `children`: Array
An array of children `upstreams`
* `target`: String
The target server composed of scheme and host, including port.
* `path`: String | Function
If provided, the matched path will be replaced with it.
* `changeOrigin`: Boolean
Whether `host` should be updated to the target upstream, passed to [http-proxy](https://github.com/nodejitsu/node-http-proxy).
* `secure`: Boolean
Whether SSL certificate should be verified for upstream.