koa-proxy icon indicating copy to clipboard operation
koa-proxy copied to clipboard

如何使用多个 host

Open janjon opened this issue 8 years ago • 3 comments

因为我的项目需要调用多个 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)));
}

janjon avatar Aug 23 '16 07:08 janjon

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.

gkaran avatar Oct 07 '16 10:10 gkaran

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

Stupidism avatar Feb 08 '17 07:02 Stupidism

这个支持多个host,https://github.com/wedog/koa-nginx

wedog avatar Jun 23 '17 08:06 wedog