Node http-proxy and express

前端 未结 4 651
孤独总比滥情好
孤独总比滥情好 2020-12-08 05:01

I\'m trying to do something like this:

// Setup prox to handle blog requests
httpProxy.createServer({
    hostnameOnly: true,
    router: {
        \'http://         


        
4条回答
  •  误落风尘
    2020-12-08 06:07

    I have used simple solution to proxified my GET/POST requests.

    var httpProxy = require('http-proxy');
    var apiProxy = httpProxy.createProxyServer();
    
    app.post("/api/*", function(req, res) {
      apiProxy.web(req, res, { target: 'http://localhost:5000'})
    });
    app.get("/api/*", function(req, res) {
      apiProxy.web(req, res, { target: 'http://localhost:5000'})
    });
    

    another easier way to handle all type of requests is:

    app.all("/api/*", function(req, res) {
      apiProxy.web(req, res, { target: 'http://localhost:5000'})
    });
    

    NOTE: above functions must be before bodyparser.

提交回复
热议问题