CartoDB-SQL-API/lib/models/cartodb-request.js

25 lines
589 B
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
module.exports = class CdbRequest {
constructor () {
// would extract "strk" from "strk.cartodb.com"
this.RE_USER_FROM_HOST = new RegExp(global.settings.user_from_host || '^([^\\.]+)\\.');
}
userByReq (req) {
const host = req.headers.host || '';
if (req.params.user) {
return req.params.user;
}
const mat = host.match(this.RE_USER_FROM_HOST);
if (!mat || mat.length !== 2) {
throw new Error(`No username found in hostname '${host}'`);
}
return mat[1];
}
};