2015-03-24 00:35:09 +08:00
|
|
|
function CdbRequest() {
|
2015-03-30 22:28:37 +08:00
|
|
|
this.RE_USER_FROM_HOST = new RegExp(global.environment.user_from_host ||
|
|
|
|
'^([^\\.]+)\\.' // would extract "strk" from "strk.cartodb.com"
|
|
|
|
);
|
2015-03-24 00:35:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CdbRequest;
|
|
|
|
|
|
|
|
|
|
|
|
CdbRequest.prototype.userByReq = function(req) {
|
|
|
|
var host = req.headers.host;
|
|
|
|
if (req.params.user) {
|
|
|
|
return req.params.user;
|
|
|
|
}
|
2015-03-30 22:28:37 +08:00
|
|
|
var mat = host.match(this.RE_USER_FROM_HOST);
|
2015-03-24 00:35:09 +08:00
|
|
|
if ( ! mat ) {
|
2015-09-18 23:12:53 +08:00
|
|
|
global.logger.error("Pattern '%s' does not match hostname '%s'", this.RE_USER_FROM_HOST, host);
|
2015-03-24 00:35:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( mat.length !== 2 ) {
|
2015-09-18 23:12:53 +08:00
|
|
|
global.logger.error("Pattern '%s' gave unexpected matches against '%s': %s", this.RE_USER_FROM_HOST, host, mat);
|
2015-03-24 00:35:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return mat[1];
|
|
|
|
};
|