Merge branch 'middlewarify' into stats-middleware
This commit is contained in:
commit
242e63716f
@ -4,10 +4,6 @@ function BaseController() {
|
||||
module.exports = BaseController;
|
||||
|
||||
BaseController.prototype.send = function(req, res, body, status, headers) {
|
||||
if (req.params.dbhost) {
|
||||
res.set('X-Served-By-DB-Host', req.params.dbhost);
|
||||
}
|
||||
|
||||
if (headers) {
|
||||
res.set(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
|
||||
@ -12,7 +12,7 @@ module.exports = function dbConnSetupMiddleware(pgConnection) {
|
||||
err.http_status = 404;
|
||||
}
|
||||
req.profiler.done('req2params');
|
||||
return next(err, req);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Add default database connection parameters
|
||||
@ -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) {
|
||||
@ -33,7 +35,7 @@ module.exports = function dbConnSetupMiddleware(pgConnection) {
|
||||
|
||||
req.profiler.done('req2params');
|
||||
|
||||
next(null, req);
|
||||
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.status(statusCode);
|
||||
|
||||
if (req.query && req.query.callback) {
|
||||
|
@ -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) {
|
||||
@ -108,7 +108,7 @@ describe('prepare-context', function() {
|
||||
locals: {}
|
||||
};
|
||||
|
||||
dbConnSetup(prepareRequest(req), res, function(err, req) {
|
||||
dbConnSetup(prepareRequest(req), res, function () {
|
||||
// wrong key resets params to no user
|
||||
assert.ok(req.params.dbuser === test_pubuser, 'could inject dbuser ('+req.params.dbuser+')');
|
||||
done();
|
||||
|
Loading…
Reference in New Issue
Block a user