Inject prepare context middleware to controllers
This commit is contained in:
@@ -9,11 +9,11 @@ var BaseController = require('./base');
|
||||
|
||||
var cors = require('../middleware/cors');
|
||||
var userMiddleware = require('../middleware/user');
|
||||
const prepareContextMiddleware = require('../middleware/context');
|
||||
|
||||
function AnalysesController(authApi, pgConnection) {
|
||||
BaseController.call(this, authApi, pgConnection);
|
||||
this.prepareContext = prepareContextMiddleware(authApi, pgConnection);
|
||||
|
||||
function AnalysesController(prepareContext) {
|
||||
BaseController.call(this);
|
||||
this.prepareContext = prepareContext;
|
||||
}
|
||||
|
||||
util.inherits(AnalysesController, BaseController);
|
||||
|
||||
@@ -15,8 +15,6 @@ var MapStoreMapConfigProvider = require('../models/mapconfig/provider/map-store-
|
||||
|
||||
var QueryTables = require('cartodb-query-tables');
|
||||
|
||||
const prepareContextMiddleware = require('../middleware/context');
|
||||
|
||||
/**
|
||||
* @param {AuthApi} authApi
|
||||
* @param {PgConnection} pgConnection
|
||||
@@ -30,9 +28,9 @@ const prepareContextMiddleware = require('../middleware/context');
|
||||
* @param {AnalysisBackend} analysisBackend
|
||||
* @constructor
|
||||
*/
|
||||
function LayergroupController(authApi, pgConnection, mapStore, tileBackend, previewBackend, attributesBackend,
|
||||
function LayergroupController(prepareContext, pgConnection, mapStore, tileBackend, previewBackend, attributesBackend,
|
||||
surrogateKeysCache, userLimitsApi, layergroupAffectedTables, analysisBackend) {
|
||||
BaseController.call(this, authApi, pgConnection);
|
||||
BaseController.call(this);
|
||||
|
||||
this.pgConnection = pgConnection;
|
||||
this.mapStore = mapStore;
|
||||
@@ -46,7 +44,7 @@ function LayergroupController(authApi, pgConnection, mapStore, tileBackend, prev
|
||||
this.dataviewBackend = new DataviewBackend(analysisBackend);
|
||||
this.analysisStatusBackend = new AnalysisStatusBackend();
|
||||
|
||||
this.prepareContext = prepareContextMiddleware(authApi, pgConnection);
|
||||
this.prepareContext = prepareContext;
|
||||
}
|
||||
|
||||
util.inherits(LayergroupController, BaseController);
|
||||
|
||||
@@ -20,8 +20,6 @@ var NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
|
||||
var NamedMapMapConfigProvider = require('../models/mapconfig/provider/named-map-provider');
|
||||
var CreateLayergroupMapConfigProvider = require('../models/mapconfig/provider/create-layergroup-provider');
|
||||
|
||||
const prepareContextMiddleware = require('../middleware/context');
|
||||
|
||||
/**
|
||||
* @param {AuthApi} authApi
|
||||
* @param {PgConnection} pgConnection
|
||||
@@ -35,11 +33,11 @@ const prepareContextMiddleware = require('../middleware/context');
|
||||
* @param {StatsBackend} statsBackend
|
||||
* @constructor
|
||||
*/
|
||||
function MapController(authApi, pgConnection, templateMaps, mapBackend, metadataBackend,
|
||||
function MapController(prepareContext, pgConnection, templateMaps, mapBackend, metadataBackend,
|
||||
surrogateKeysCache, userLimitsApi, layergroupAffectedTables, mapConfigAdapter,
|
||||
statsBackend) {
|
||||
|
||||
BaseController.call(this, authApi, pgConnection);
|
||||
BaseController.call(this);
|
||||
|
||||
this.pgConnection = pgConnection;
|
||||
this.templateMaps = templateMaps;
|
||||
@@ -53,7 +51,7 @@ function MapController(authApi, pgConnection, templateMaps, mapBackend, metadata
|
||||
this.resourceLocator = new ResourceLocator(global.environment);
|
||||
|
||||
this.statsBackend = statsBackend;
|
||||
this.prepareContext = prepareContextMiddleware(authApi, pgConnection);
|
||||
this.prepareContext = prepareContext;
|
||||
}
|
||||
|
||||
util.inherits(MapController, BaseController);
|
||||
|
||||
@@ -9,11 +9,10 @@ var BaseController = require('./base');
|
||||
var cors = require('../middleware/cors');
|
||||
var userMiddleware = require('../middleware/user');
|
||||
var allowQueryParams = require('../middleware/allow-query-params');
|
||||
const prepareContextMiddleware = require('../middleware/context');
|
||||
|
||||
function NamedMapsController(authApi, pgConnection, namedMapProviderCache, tileBackend, previewBackend,
|
||||
function NamedMapsController(prepareContext, namedMapProviderCache, tileBackend, previewBackend,
|
||||
surrogateKeysCache, tablesExtentApi, metadataBackend) {
|
||||
BaseController.call(this, authApi, pgConnection);
|
||||
BaseController.call(this);
|
||||
|
||||
this.namedMapProviderCache = namedMapProviderCache;
|
||||
this.tileBackend = tileBackend;
|
||||
@@ -21,7 +20,7 @@ function NamedMapsController(authApi, pgConnection, namedMapProviderCache, tileB
|
||||
this.surrogateKeysCache = surrogateKeysCache;
|
||||
this.tablesExtentApi = tablesExtentApi;
|
||||
this.metadataBackend = metadataBackend;
|
||||
this.prepareContext = prepareContextMiddleware(authApi, pgConnection);
|
||||
this.prepareContext = prepareContext;
|
||||
}
|
||||
|
||||
util.inherits(NamedMapsController, BaseController);
|
||||
|
||||
@@ -15,8 +15,8 @@ var userMiddleware = require('../middleware/user');
|
||||
* @param {TemplateMaps} templateMaps
|
||||
* @constructor
|
||||
*/
|
||||
function NamedMapsAdminController(authApi, pgConnection, templateMaps) {
|
||||
BaseController.call(this, authApi, pgConnection);
|
||||
function NamedMapsAdminController(authApi, templateMaps) {
|
||||
BaseController.call(this);
|
||||
|
||||
this.authApi = authApi;
|
||||
this.templateMaps = templateMaps;
|
||||
|
||||
@@ -47,6 +47,8 @@ var StatsBackend = require('./backends/stats');
|
||||
const lzmaMiddleware = require('./middleware/lzma');
|
||||
const errorMiddleware = require('./middleware/error-middleware');
|
||||
|
||||
const prepareContextMiddleware = require('./middleware/context');
|
||||
|
||||
module.exports = function(serverOptions) {
|
||||
// Make stats client globally accessible
|
||||
global.statsClient = StatsClient.getInstance(serverOptions.statsd);
|
||||
@@ -209,6 +211,8 @@ module.exports = function(serverOptions) {
|
||||
|
||||
var versions = getAndValidateVersions(serverOptions);
|
||||
|
||||
const prepareContext = prepareContextMiddleware(authApi, pgConnection);
|
||||
|
||||
/*******************************************************************************************************************
|
||||
* Routing
|
||||
******************************************************************************************************************/
|
||||
@@ -216,7 +220,7 @@ module.exports = function(serverOptions) {
|
||||
const routerLayergroup = express.Router();
|
||||
|
||||
new controller.Layergroup(
|
||||
authApi,
|
||||
prepareContext,
|
||||
pgConnection,
|
||||
mapStore,
|
||||
tileBackend,
|
||||
@@ -231,7 +235,7 @@ module.exports = function(serverOptions) {
|
||||
app.use(app.base_url_mapconfig, routerLayergroup);
|
||||
|
||||
new controller.Map(
|
||||
authApi,
|
||||
prepareContext,
|
||||
pgConnection,
|
||||
templateMaps,
|
||||
mapBackend,
|
||||
@@ -244,8 +248,7 @@ module.exports = function(serverOptions) {
|
||||
).register(app);
|
||||
|
||||
new controller.NamedMaps(
|
||||
authApi,
|
||||
pgConnection,
|
||||
prepareContext,
|
||||
namedMapProviderCache,
|
||||
tileBackend,
|
||||
previewBackend,
|
||||
@@ -255,11 +258,11 @@ module.exports = function(serverOptions) {
|
||||
).register(app);
|
||||
|
||||
const namedMapsAdminRouter = express.Router();
|
||||
new controller.NamedMapsAdmin(authApi, pgConnection, templateMaps).register(namedMapsAdminRouter);
|
||||
new controller.NamedMapsAdmin(authApi, templateMaps).register(namedMapsAdminRouter);
|
||||
app.use(app.base_url_templated, namedMapsAdminRouter);
|
||||
|
||||
const analysisRouter = express.Router();
|
||||
new controller.Analyses(authApi, pgConnection).register(analysisRouter);
|
||||
new controller.Analyses(prepareContext).register(analysisRouter);
|
||||
app.use(app.base_url_mapconfig, analysisRouter);
|
||||
|
||||
new controller.ServerInfo(versions).register(app);
|
||||
|
||||
Reference in New Issue
Block a user