node.js - gulp配置时使用http-proxy-middleware做代理,有人知道怎么配置多重代理吗?
PHP中文网
PHP中文网 2017-04-17 15:03:07
0
2
749

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中文网

认证0级讲师

reply all(2)
巴扎黑

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...

洪涛

@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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template