2013-12-18 18:57:46 +08:00
|
|
|
/**
|
|
|
|
* this module provides cartodb-specific interpretation
|
|
|
|
* of request headers
|
|
|
|
*/
|
|
|
|
|
2014-08-05 08:29:07 +08:00
|
|
|
function CartodbRequest() {
|
2013-12-18 18:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CartodbRequest;
|
|
|
|
|
2014-08-05 08:29:07 +08:00
|
|
|
CartodbRequest.prototype.userByReq = function(req) {
|
2013-12-18 18:57:46 +08:00
|
|
|
var host = req.headers.host;
|
2014-08-05 08:29:07 +08:00
|
|
|
var mat = host.match(re_userFromHost);
|
2013-12-18 18:57:46 +08:00
|
|
|
if ( ! mat ) {
|
2014-08-05 08:29:07 +08:00
|
|
|
console.error("ERROR: user pattern '" + re_userFromHost + "' does not match hostname '" + host + "'");
|
2013-12-18 18:57:46 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// console.log("Matches: "); console.dir(mat);
|
|
|
|
if ( ! mat.length === 2 ) {
|
2014-08-05 08:29:07 +08:00
|
|
|
console.error("ERROR: pattern '" + re_userFromHost + "' gave unexpected matches against '" + host + "': " + mat);
|
2013-12-18 18:57:46 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return mat[1];
|
|
|
|
};
|
|
|
|
|
2014-08-05 08:29:07 +08:00
|
|
|
var re_userFromHost = new RegExp(
|
|
|
|
global.settings.user_from_host || '^([^\\.]+)\\.' // would extract "strk" from "strk.cartodb.com"
|
|
|
|
);
|