Merge branch 'middlewarify' into res-locals

This commit is contained in:
Simon Martín
2017-10-09 10:55:43 +02:00
4 changed files with 5 additions and 12 deletions
-4
View File
@@ -7,10 +7,6 @@ module.exports = BaseController;
// jshint maxcomplexity:9
BaseController.prototype.send = function(req, res, body, status, headers) {
if (res.locals.dbhost) {
res.set('X-Served-By-DB-Host', res.locals.dbhost);
}
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
if (headers) {
@@ -1,7 +1,7 @@
const _ = require('underscore');
module.exports = function dbConnSetupMiddleware(pgConnection) {
return function (req, res, next) {
return function dbConnSetup(req, res, next) {
const user = res.locals.user;
pgConnection.setDBConn(user, res.locals, (err) => {
@@ -22,7 +22,8 @@ module.exports = function dbConnSetupMiddleware(pgConnection) {
dbport: global.environment.postgres.port
});
res.set('X-Served-By-DB-Host', req.params.dbhost);
req.profiler.done('req2params');
next(null);
@@ -31,10 +31,6 @@ module.exports = function errorMiddleware (/* options */) {
errors_with_context: allErrors.map(errorMessageWithContext)
};
if (res.locals && res.locals.dbhost) {
res.set('X-Served-By-DB-Host', res.locals.dbhost);
}
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
res.status(statusCode);
+2 -2
View File
@@ -88,7 +88,7 @@ describe('prepare-context', function() {
it('sets dbname from redis metadata', function(done){
var req = {headers: { host:'localhost' }, query: {} };
var res = {};
var res = { set: function () {} };
dbConnSetup(prepareRequest(req), prepareResponse(res), function(err) {
if ( err ) { done(err); return; }
@@ -104,7 +104,7 @@ describe('prepare-context', function() {
it('sets also dbuser for authenticated requests', function(done){
var req = { headers: { host: 'localhost' }, query: { map_key: '1234' }};
var res = {};
var res = { set: function () {} };
// FIXME: review authorize-pgconnsetup workflow, It might we are doing authorization twice.
authorize(prepareRequest(req), prepareResponse(res), function (err) {