I use node-http proxy module to run application with reverse proxy which is working as expected, in some cases user want to run application immediately which the status of it in progress (the app is not up yet) and it can take about 3-15 sec until the app is up and running; in this case user will get error from the proxy.
proxy.web(req, res, {
target: 'http://' + hostname + ':' + Port
console.log("App------------->Proxy App" );
});
proxy.on('proxyReq', function(proxyReq, req, res, options) {
console.log("App------------->Proxy Request" );
});
proxy.on('error', function (err, req, res) {
console.log("App------------->Proxy Error" );
res.end('Something went wrong');
});
// Listen for the `proxyRes` event on `proxy`.
proxy.on('proxyRes', function (proxyRes, req, res) {
console.log("App------------->Proxy Response" )
var respState = res.statusCode
});
In case of error the stack in the log is like
- Proxy app
- Proxy Request
- Proxy Error
In this case user will run the app url in the browser and first will get the error and after few seconds when he refresh the browser the app will run OK. Any suggestion how to solve this issue ?
I thought about building some API which examine the proxyRes status(like call it every 1 sec and see if the response is 200 and not send the error before like "check it with timeout" and if after 10 sec there is not response maybe to send the error but not sure how to do it and if its good approach... any idea? or maybe via webSoket but not sure how to do that ...
This is the open source Im using https://github.com/nodejitsu/node-http-proxy