koa-proxy-url
v1.0.9
Published
Proxy middleware for koa
Downloads
9
Maintainers
Readme
koa-proxy-url
- Proxy middleware for koa
- clone from koa-proxy
- added: option.url support function(http){return url} to free url
- added:option.customPath
- added:option.customHost
- added:this.callBack
Install
$ npm install koa-proxy-url
Usage
Execution order:
- customHost
- customPath
- options.url (if the type of url is function)
app.use(proxy({
match: /\/proxy/,
customHost: function (http) {
let cutomHost = null;
let host = http.host;
cutomHost = host == 'test.com' ? 'custom.com' : host;
return cutomHost;
},
customPath: function (http, options) {
let path = http.path
if (options.host == 'test.com') {
path = '/test' + path;
}
return path;
},
url: function (http) {
let source = httpQueryParse(http.request).source;
if (source != undefined) {
return source
} else {
return null;
}
},
}));
app.use(function *(next) {
this.callBack = function (res) {
console.log(res.statusCode);
console.log(res.body);
console.log(res.headers.date);
}
})
LICENSE
Copyright (c) 2016 popomore. Licensed under the MIT license.