1
0
Fork 0

Added req.absoluteUrl method.

This commit is contained in:
Alan Plum 2015-05-07 01:15:20 +02:00
parent 6dd786fb3c
commit 59fd94efd3
1 changed files with 8 additions and 0 deletions

View File

@ -45,6 +45,14 @@ actions.defineHttp({
prefix : true,
callback : function (req, res) {
req.absoluteUrl = function (url) {
var protocol = req.headers["x-forwarded-proto"] || req.protocol;
var address = req.headers["x-forwarded-host"] || req.headers.host;
if (!address) {
address = (req.server.address === '0.0.0.0' ? 'localhost' : req.server.address) + ':' + req.server.port;
}
return protocol + "://" + address + '/_db/' + encodeURIComponent(req.database) + (url || req.url);
};
try {
actions.routeRequest(req, res);
}