Skip to content

Do I have to have the other node apps on? #2

Description

@junerockwell

Let's say that I have 3 apps; #1 is the proxy and using this http-proxy-rules, #2 nodeapp1 was built using Restify and #3 nodeapp2 was built using Restify as well. I'm using PM2 to keep them alive.

My proxy server's main.js looks like this:

var proxyRules = new HttpProxyRules({
     rules: {
         '.*/test': 'http://localhost:8081', // Rule (1) 
         '.*/test2/': 'http://localhost:8082' // Rule (2) 
    },
    default: 'http://localhost:8080' // default target 
});
...
http.createServer(function(req, res) {
   var target = proxyRules.match(req);
   if (target) {
       return proxy.web(req, res, {
             target: target
  });
}

   res.writeHead(500, { 'Content-Type': 'text/plain' });
   res.end('The request url and path did not match any of the listed rules!');
}).listen(8080, cb);

As you can see, I didn't follow your example. In your example, you used port 6061 on the proxy server which is a different number from the test and test2 which both have the same port number 8080 because your specific example didn't work for me.

Question #1: I would like to know how you did this. If possible, I would like to know how to use the same hostname and the same port number for all 3 apps.

Question #2: How did you come up with the a url that has the same hostname and port number but different different paths which are cool and cool2?

Question #3: If I copy exactly your example, do I have to have nodeapp1 and nodeapp2 running or do I just have the proxy server run?

My nodeapp1's app.js ends in this:

app.listen(8081, function() {
    console.log('nodeapp1');
 });

Same for nodeapp2:

app.listen(8082, function() {
    console.log('nodeapp1');
 });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions