search

Home  >  Q&A  >  body text

node.js - gulp配置时使用http-proxy-middleware做代理,有人知道怎么配置多重代理吗?

gulp配置时使用http-proxy-middleware做代理,有人知道怎么配置多重代理吗?

gulp.task('server', function() {
    connect.server({
        livereload: true,
        root: "./output",
        port: 8080,
        middleware: function(connect, opt) {
            return [
                proxy('/test',{
                    target: 'http://localhost:8000',
                    changeOrigin: true,
                })
            ]
        }
    });
});
PHP中文网PHP中文网2779 days ago757

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 15:05:07

    return doesn’t return an array, try writing more proxies

    gulp.task('server', function() {
        connect.server({
            livereload: true,
            root: "./output",
            port: 8080,
            middleware: function(connect, opt) {
                return [
                    proxy('/test',{
                        target: 'http://localhost:8000',
                        changeOrigin: true,
                    }),
                    proxy('/other-test',{
                        target: 'http://localhost:9000',
                        changeOrigin: true,
                    })
                ]
            }
        });
    });

    Official example:
    https://github.com/chimurai/h...

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:05:07

    @hjzheng It’s the same, but the proxy is written separately

    var proxy1 = proxyMiddleware('/api', {
        target: 'http://huggies.kmapp.net',
        changeOrigin: true,
        pathRewrite: {
            '^/api' : '/campaign_huggies/t3store_freeuse'      // rewrite paths
        },
      });

    Then configure middleware: [proxy1, proxy2] like this

    reply
    0
  • Cancelreply