not move db params to res.locals.db

This commit is contained in:
Simon Martín 2017-09-29 11:07:11 +02:00
parent f824fc5243
commit b4d03c074a
4 changed files with 7 additions and 8 deletions

View File

@ -105,7 +105,7 @@ AuthApi.prototype.authorize = function(req, res, callback) {
} }
// authorized by api key, login as the given username and stop // authorized by api key, login as the given username and stop
self.pgConnection.setDBAuth(user, res.locals.db, function(err) { self.pgConnection.setDBAuth(user, res.locals, function(err) {
callback(err, true); // authorized (or error) callback(err, true); // authorized (or error)
}); });
}, },
@ -128,7 +128,7 @@ AuthApi.prototype.authorize = function(req, res, callback) {
return callback(null, false); return callback(null, false);
} }
self.pgConnection.setDBAuth(user, res.locals.db, function(err) { self.pgConnection.setDBAuth(user, res.locals, function(err) {
req.profiler.done('setDBAuth'); req.profiler.done('setDBAuth');
callback(err, true); // authorized (or error) callback(err, true); // authorized (or error)
}); });

View File

@ -44,7 +44,7 @@ AnalysesController.prototype.catalog = function (req, res, next) {
step( step(
function catalogQuery() { function catalogQuery() {
var pg = new PSQL(dbParamsFromReqParams(res.locals.db)); var pg = new PSQL(dbParamsFromReqParams(res.locals));
getMetadata(username, pg, this); getMetadata(username, pg, this);
}, },
function prepareResponse(err, results) { function prepareResponse(err, results) {

View File

@ -7,8 +7,8 @@ module.exports = BaseController;
// jshint maxcomplexity:9 // jshint maxcomplexity:9
BaseController.prototype.send = function(req, res, body, status, headers) { BaseController.prototype.send = function(req, res, body, status, headers) {
if (res.locals.db.dbhost) { if (res.locals.dbhost) {
res.set('X-Served-By-DB-Host', res.locals.db.dbhost); res.set('X-Served-By-DB-Host', res.locals.dbhost);
} }
res.set('X-Tiler-Profiler', req.profiler.toJSONString()); res.set('X-Tiler-Profiler', req.profiler.toJSONString());

View File

@ -4,8 +4,7 @@ module.exports = function dbConnSetupMiddleware(pgConnection) {
return function (req, res, next) { return function (req, res, next) {
const user = req.context.user; const user = req.context.user;
res.locals.db = {} pgConnection.setDBConn(user, res.locals, (err) => {
pgConnection.setDBConn(user, res.locals.db, (err) => {
if (err) { if (err) {
if (err.message && -1 !== err.message.indexOf('name not found')) { if (err.message && -1 !== err.message.indexOf('name not found')) {
err.http_status = 404; err.http_status = 404;
@ -16,7 +15,7 @@ module.exports = function dbConnSetupMiddleware(pgConnection) {
// Add default database connection parameters // Add default database connection parameters
// if none given // if none given
_.defaults(res.locals.db, { _.defaults(res.locals, {
dbuser: global.environment.postgres.user, dbuser: global.environment.postgres.user,
dbpassword: global.environment.postgres.password, dbpassword: global.environment.postgres.password,
dbhost: global.environment.postgres.host, dbhost: global.environment.postgres.host,