koa-proxypass v0.1.2
koa-proxypass
A proxy-pass server for koa.
Installation
$ npm install koa-proxypassUsage
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:
upstreamsan 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
RegExporFunction (param *responding-value*)for smart test orAnyfor exact match.The function will have the request object with
method,path,headerattributes as the only parameter.children: ArrayAn array of children
upstreamstarget: StringThe target server composed of scheme and host, including port.
path: String | FunctionIf provided, the matched path will be replaced with it.
changeOrigin: BooleanWhether
hostshould be updated to the target upstream, passed to http-proxy.secure: BooleanWhether SSL certificate should be verified for upstream.