diff --git a/lib/cartodb/controllers/map/anonymous.js b/lib/cartodb/controllers/map/anonymous.js index a8b7f353..d90820c4 100644 --- a/lib/cartodb/controllers/map/anonymous.js +++ b/lib/cartodb/controllers/map/anonymous.js @@ -9,6 +9,7 @@ const credentials = require('../../middleware/credentials'); const dbConnSetup = require('../../middleware/db-conn-setup'); const authorize = require('../../middleware/authorize'); const initProfiler = require('./middlewares/init-profiler'); +const checkJsonContentType = require('./middlewares/check-json-content-type'); const cacheControlHeader = require('../../middleware/cache-control-header'); const cacheChannelHeader = require('../../middleware/cache-channel-header'); const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); @@ -110,18 +111,6 @@ AnonymousMapController.prototype.composeCreateMapMiddleware = function () { ]; }; -function checkJsonContentType () { - return function checkJsonContentTypeMiddleware(req, res, next) { - if (req.method === 'POST' && !req.is('application/json')) { - return next(new Error('POST data must be of type application/json')); - } - - req.profiler.done('checkJsonContentTypeMiddleware'); - - next(); - }; -} - function checkCreateLayergroup () { return function checkCreateLayergroupMiddleware (req, res, next) { if (req.method === 'GET') { diff --git a/lib/cartodb/controllers/map/middlewares/check-json-content-type.js b/lib/cartodb/controllers/map/middlewares/check-json-content-type.js new file mode 100644 index 00000000..05aa6f26 --- /dev/null +++ b/lib/cartodb/controllers/map/middlewares/check-json-content-type.js @@ -0,0 +1,11 @@ +module.exports = function checkJsonContentType () { + return function checkJsonContentTypeMiddleware(req, res, next) { + if (req.method === 'POST' && !req.is('application/json')) { + return next(new Error('POST data must be of type application/json')); + } + + req.profiler.done('checkJsonContentTypeMiddleware'); + + next(); + }; +}; diff --git a/lib/cartodb/controllers/map/named.js b/lib/cartodb/controllers/map/named.js index ecaf3917..73822421 100644 --- a/lib/cartodb/controllers/map/named.js +++ b/lib/cartodb/controllers/map/named.js @@ -5,6 +5,7 @@ const credentials = require('../../middleware/credentials'); const dbConnSetup = require('../../middleware/db-conn-setup'); const authorize = require('../../middleware/authorize'); const initProfiler = require('./middlewares/init-profiler'); +const checkJsonContentType = require('./middlewares/check-json-content-type'); const cacheControlHeader = require('../../middleware/cache-control-header'); const cacheChannelHeader = require('../../middleware/cache-channel-header'); const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); @@ -120,18 +121,6 @@ NamedMapController.prototype.composeInstantiateTemplateMiddleware = function () ]; }; -function checkJsonContentType () { - return function checkJsonContentTypeMiddleware(req, res, next) { - if (req.method === 'POST' && !req.is('application/json')) { - return next(new Error('POST data must be of type application/json')); - } - - req.profiler.done('checkJsonContentTypeMiddleware'); - - next(); - }; -} - function checkInstantiteLayergroup () { return function checkInstantiteLayergroupMiddleware(req, res, next) { if (req.method === 'GET') {