I have a Node Server A already running, which handles my all webservice call. I want Server A to redirect all webservice calls to my local server whenever I start my local server. I've already tried node module 'http-proxy'. I made a call to notify Server A that my local server is up and start redirect all calls to my local server, but it doesn't fulfill my purpose. Below is an example and both servers are my local servers, keeping in mind that I want to redirect all calls from Live Server to my Local Server.
On Server A:
var http = require('http'),
httpProxy = require('http-proxy');
exports.redirectCalls = function(req, res){
var params = req.params;
var target = {target: 'http://'+params.ip+':3000'};
if (params.ip) {
var proxy = httpProxy.createServer();
proxy.web(req, res, target);
res.send({Message: "Proxy Created"});
}
else{
res.send({Message: "Response Error"});
}
};
exports.callsRedirected = function(req, res){
res.send({Message: "Listening on 4000"});
};
On Server B (My Local Server):
var request = require("request");
exports.showAlive = function(req, res){
var params = req.params;
if(params.ip){
var url = "http://localhost:4000/redirectCalls/" + params.ip;
request.get(url, function (error, response) {
if (response)
res.send(response.body);
else if (error)
res.send(error);
else
res.send({Message: "Couldn't make the call to 4000"});
});
}
else{
res.send({Message: "Empty response"});
}
};
exports.callsRedirected = function(req, res){
res.send({Message: "Listening on 3000"});
};
Basically I don't want to make an additional call to notify Server A that my local Server B is up and running. I want to build a socket through which all webservice calls from Server A gets through, whenever Server B(my local server) is up. I thought about socket.io but I think it is not built for this purpose. Building a VPN connection at runtime could do this I think, but I would need help to set it up, if it could be done.
Please suggest any node module that can do it for me or some strategy to make it happened.