0

I have two nodejs apps that are running at localhost. 1st is listen on port 8080 and the second on port 8081 and i want to have single point where this apps are visible.

For example:

http://localhost/app1 --> http://localhost:8080
http://localhost/app2 --> http://localhost:8081

Saw that this can be done with http-proxy but can't make it to work. Every example that i run is returning Error: Must provide a proper URL as target

My code is:

var http = require('http');
var httpProxy = require('http-proxy');

var options = {
    pathnameOnly: true,
    router: {
        '/app1': 'http://localhost:8080',
        '/app2': 'http://localhost:8081'
  }
};

var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);

What is possible to be missing?

Stefan Stoichev
  • 4,615
  • 3
  • 31
  • 51
  • 1
    I cannot find those options in the standard http-proxy package, but something can be found here: https://github.com/donasaur/http-proxy-rules – datashaman Apr 11 '16 at 06:37
  • its kinda working with the rules but this way for the css/js files 404 is returned – Stefan Stoichev Apr 12 '16 at 06:05
  • 1
    that will happen. the application doesn't know that it's being served in a subfolder. you must configure the base URL for the applications so they know they are within /app1 and /app2. Look here for the answer to that one: http://stackoverflow.com/questions/4375554/is-it-possible-to-set-a-base-url-for-nodejs-app/ – datashaman Apr 13 '16 at 05:18

0 Answers0