Add function to read database host from redis

This commit is contained in:
Luis Bosque
2013-12-17 17:17:14 +01:00
committed by Sandro Santilli
parent d305dbd468
commit 8d1b394df1
+20
View File
@@ -100,6 +100,26 @@ module.exports = function() {
});
};
/**
* Get the database host this particular subdomain/username
*
* @param req - standard express req object. importantly contains host information
* @param callback
*/
me.getDatabaseHost= function(req, callback) {
// strip subdomain from header host
var username = req.headers.host.split('.')[0];
var redisKey = _.template(this.user_key, {username: username});
this.retrieve(this.user_metadata_db, redisKey, 'database_host', function(err, dbname) {
if ( err ) callback(err, null);
else if ( dbname === null ) {
callback(new Error("missing " + username + "'s dbuser in redis (try CARTODB/script/restore_redis)"), null);
}
else callback(err, dbname);
});
};
/**
* Check the user map key for this particular subdomain/username
*