2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-22 01:07:24 +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;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
CdbRequest.prototype.userByReq = function (req) {
|
2015-09-30 22:31:56 +08:00
|
|
|
var host = req.headers.host || '';
|
2015-03-24 00:35:09 +08:00
|
|
|
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);
|
2019-10-22 01:07:24 +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;
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
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];
|
|
|
|
};
|