Extract initProfiler middlewar

This commit is contained in:
Daniel García Aubert 2018-03-28 12:45:03 +02:00
parent d8d681e8bc
commit 64d540f23b
3 changed files with 11 additions and 20 deletions

View File

@ -8,6 +8,7 @@ const cleanUpQueryParams = require('../../middleware/clean-up-query-params');
const credentials = require('../../middleware/credentials'); const credentials = require('../../middleware/credentials');
const dbConnSetup = require('../../middleware/db-conn-setup'); const dbConnSetup = require('../../middleware/db-conn-setup');
const authorize = require('../../middleware/authorize'); const authorize = require('../../middleware/authorize');
const initProfiler = require('./middlewares/init-profiler');
const cacheControlHeader = require('../../middleware/cache-control-header'); const cacheControlHeader = require('../../middleware/cache-control-header');
const cacheChannelHeader = require('../../middleware/cache-channel-header'); const cacheChannelHeader = require('../../middleware/cache-channel-header');
const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
@ -109,16 +110,6 @@ AnonymousMapController.prototype.composeCreateMapMiddleware = function () {
]; ];
}; };
function initProfiler (isTemplateInstantiation) {
const operation = isTemplateInstantiation ? 'instance_template' : 'createmap';
return function initProfilerMiddleware (req, res, next) {
req.profiler.start(`windshaft-cartodb.${operation}_${req.method.toLowerCase()}`);
req.profiler.done(`${operation}.initProfilerMiddleware`);
next();
};
}
function checkJsonContentType () { function checkJsonContentType () {
return function checkJsonContentTypeMiddleware(req, res, next) { return function checkJsonContentTypeMiddleware(req, res, next) {
if (req.method === 'POST' && !req.is('application/json')) { if (req.method === 'POST' && !req.is('application/json')) {

View File

@ -0,0 +1,9 @@
module.exports = function initProfiler (isTemplateInstantiation) {
const operation = isTemplateInstantiation ? 'instance_template' : 'createmap';
return function initProfilerMiddleware (req, res, next) {
req.profiler.start(`windshaft-cartodb.${operation}_${req.method.toLowerCase()}`);
req.profiler.done(`${operation}.initProfilerMiddleware`);
next();
};
};

View File

@ -4,6 +4,7 @@ const cleanUpQueryParams = require('../../middleware/clean-up-query-params');
const credentials = require('../../middleware/credentials'); const credentials = require('../../middleware/credentials');
const dbConnSetup = require('../../middleware/db-conn-setup'); const dbConnSetup = require('../../middleware/db-conn-setup');
const authorize = require('../../middleware/authorize'); const authorize = require('../../middleware/authorize');
const initProfiler = require('./middlewares/init-profiler');
const cacheControlHeader = require('../../middleware/cache-control-header'); const cacheControlHeader = require('../../middleware/cache-control-header');
const cacheChannelHeader = require('../../middleware/cache-channel-header'); const cacheChannelHeader = require('../../middleware/cache-channel-header');
const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
@ -119,16 +120,6 @@ NamedMapController.prototype.composeInstantiateTemplateMiddleware = function ()
]; ];
}; };
function initProfiler (isTemplateInstantiation) {
const operation = isTemplateInstantiation ? 'instance_template' : 'createmap';
return function initProfilerMiddleware (req, res, next) {
req.profiler.start(`windshaft-cartodb.${operation}_${req.method.toLowerCase()}`);
req.profiler.done(`${operation}.initProfilerMiddleware`);
next();
};
}
function checkJsonContentType () { function checkJsonContentType () {
return function checkJsonContentTypeMiddleware(req, res, next) { return function checkJsonContentTypeMiddleware(req, res, next) {
if (req.method === 'POST' && !req.is('application/json')) { if (req.method === 'POST' && !req.is('application/json')) {