Node http-proxy and express

前端 未结 4 642
孤独总比滥情好
孤独总比滥情好 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 05:42

    A very straightforward solution which works seamlessly, and with cookies/authentication as well, using express-http-proxy:

    var proxy = require('express-http-proxy');
    
    var blogProxy = proxy('localhost/blog:2368', {
        forwardPath: function (req, res) {
            return require('url').parse(req.url).path;
        }
    });
    

    And then simply:

    app.use("/blog/*", blogProxy);
    

    I know I'm late to join this party, but I hope this helps someone.

提交回复
热议问题