koa-proxy
koa-proxy copied to clipboard
如何使用多个 host
因为我的项目需要调用多个 api, 请问如何配置多个 代理,
development: (config) => ({
compiler_public_path: `http://${config.server_host}:${config.server_port}/`,
proxy: {
enabled: true,
options: {
host: 'http://192.168.8.14:1338',
match: /^\/api\/.*/,
},
option2: {
host: 'http://apiv2.muzhifm.com',
match: /^\/muzhifmApi\/.*/,
map: (path) => {
console.log(path.replace('muzhifmApi', ''));
return path.replace('/muzhifmApi', '');
},
},
},
}),
我的代码是这样的,可是第二个不能成功.
if (config.proxy && config.proxy.enabled) {
app.use(convert(proxy(config.proxy.options)));
app.use(convert(proxy(config.proxy.option2)));
}
I am having the same issue. I need to proxy to two different hosts (one for http and one for websockets) and cannot make this work.
I faced the same problem before. We used an individual nginx proxy for frond-end static deployment. So in develop-env I just send all request to that nginx proxy. Or you can config your own nginx proxy in your local environment
这个支持多个host,https://github.com/wedog/koa-nginx