I have two instances of the same node app running on port 3000
and 4000
.
I would like to have the following behavior:
https://localhost/dev ==> http://localhost:3000
https://localhost/prod ==> http:// localhost:4000
I have the following proxy in place:
var fs = require('fs'),
httpProxy = require('http-proxy');
var PATH_TO_KEY = "/home/wow/browser.key",
PATH_TO_CERT = "/home/wow/browser.crt",
PATH_TO_CHAIN = "";
var options = {
ssl: {
key: fs.readFileSync(PATH_TO_KEY, 'utf8'),
cert: fs.readFileSync(PATH_TO_CERT, 'utf8'),
//ca : fs.readFileSync(PATH_TO_CHAIN, 'utf8')
},
target: "http://localhost:4000", // this is prod
ws: true,
xfwd: true,
router: {
'https://localhost/dev': 'http://127.0.0.1:3000/',
'https://localhost/prod': 'http://127.0.0.1:4000/',
},
pathRewrite: {
'^/dev' : '/', // remove /dev/ path
'^/prod' : '/' // remove /prod/ path
},
};
var server = httpProxy.createProxyServer(options).listen(443);
However, when I visit either https://localhost/dev
or https://localhost/prod
, the following happens:
- It always redirects to the
target
which is specified and not any of the urls specified in therouter
. - The pathRewrite does not seem to happen since the I always end up at
target/prod
ortarget/dev
. The path for /dev and /prod do not exist and hence I get a page cannot be displayed error.
I'm not sure where I'm going wrong with this. Could someone help?
Thanks.