Is it possible to block a route if the request is not coming from the server? I have a http client installed on the server that makes a get request to a web service that I dont want to be public. The problem is that the http client is not logged in the application an is seen as an anonymous user by the server.
This is what I tried so far, but I dont know where in the req I should look for the ip of the requerer or if its the correct way to achieve what I want to do:
function isFromServer (req, res, next) {
if(req.ip === '127.0.0.1') return next();
else {
var err = new Error('Not Found');
err.status = 404;
return next(err);
}
}
//the webservice I want to allow only to the http client installed on the server
router.get('/[0-9]{3}$', isFromServer, function(req, res, next){
var codecs = req.url.split('/')[1];
res.render('metadata', {codecs: codecs});
});