I am using nodejs and expressjs. I wonder if there is something like request.headers.protocol in the clientRequest object. I would like to build the baseUrl for
For pure NodeJS (this works locally and deployed, e.g. behind Nginx):
function getProtocol (req) {
var proto = req.connection.encrypted ? 'https' : 'http';
// only do this if you trust the proxy
proto = req.headers['x-forwarded-proto'] || proto;
return proto.split(/\s*,\s*/)[0];
}