Set X-Served-By-DB-Host header in db-conn-setup middleware

This commit is contained in:
Daniel García Aubert
2017-10-05 18:05:46 +02:00
parent 678fbb1c8f
commit c70b8cb5bf
4 changed files with 5 additions and 11 deletions
-4
View File
@@ -7,10 +7,6 @@ module.exports = BaseController;
// jshint maxcomplexity:9
BaseController.prototype.send = function(req, res, body, status, headers) {
if (req.params.dbhost) {
res.set('X-Served-By-DB-Host', req.params.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 = req.context.user;
// FIXME: this function shouldn't be able to change `req.params`. It should return an
@@ -24,6 +24,8 @@ module.exports = function dbConnSetupMiddleware(pgConnection) {
dbport: global.environment.postgres.port
});
res.set('X-Served-By-DB-Host', req.params.dbhost);
// FIXME: Temporary hack to share data between middlewares. Express overrides req.params to
// parse url params to an object and it's performed after matching path and controller.
if (!res.locals) {
@@ -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
@@ -68,7 +68,7 @@ describe('prepare-context', function() {
it('sets dbname from redis metadata', function(done){
var req = {headers: { host:'localhost' }, query: {}, locals: {} };
var res = {};
var res = { set: function () {} };
dbConnSetup(prepareRequest(req), res, function(err) {
if ( err ) { done(err); return; }
@@ -84,7 +84,7 @@ describe('prepare-context', function() {
it('sets also dbuser for authenticated requests', function(done){
var req = { headers: { host: 'localhost' }, query: { map_key: '1234' }, locals: {} };
var res = {};
var res = { set: function () {} };
// FIXME: review authorize-pgconnsetup workflow, It might we are doing authorization twice.
authorize(prepareRequest(req), res, function (err) {