Node http-proxy and express

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

    I got this working.

    • Install Ghost and make sure it's working property (default port is 2368)
    • Create your node web app using express (listen on port 80) - nothing special here
    • Install node-http-proxy npm install http-proxy in your web app
    • Create wildcard route for /blog* that proxies requests to Ghost service

      var httpProxy = require('http-proxy');
      
      var proxy = new httpProxy.RoutingProxy();
      app.get('/blog*', function (req, res, next) {
        proxy.proxyRequest(req, res ,{
          host: 'moserlap.splitvr.com',
          port: 2368  
        });
      });
      
    • Update the Ghost config to use a sub directory (only supported in 0.4.0+)

      config = {
        // ### Development **(default)**
        development: {
        // The url to use when providing links to the site, E.g. in RSS and email.
        url: 'http://127.0.0.1/blog',
      ...
      
    • You should now be able to hit http://yoursite.com/blog and all routes work.

提交回复
热议问题