Extract db-conn-setup middleware for prepare-context
This commit is contained in:
parent
f49d7478d7
commit
afff06c7e6
@ -1,9 +1,11 @@
|
||||
var PSQL = require('cartodb-psql');
|
||||
var cors = require('../middleware/cors');
|
||||
var userMiddleware = require('../middleware/user');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
|
||||
function AnalysesController(prepareContext) {
|
||||
function AnalysesController(prepareContext, pgConnection) {
|
||||
this.prepareContext = prepareContext;
|
||||
this.pgConnection = pgConnection;
|
||||
}
|
||||
|
||||
module.exports = AnalysesController;
|
||||
@ -14,6 +16,7 @@ AnalysesController.prototype.register = function (app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createPGClient(),
|
||||
getDataFromQuery({ queryTemplate: catalogQueryTpl, key: 'catalog' }),
|
||||
getDataFromQuery({ queryTemplate: tablesQueryTpl, key: 'tables' }),
|
||||
|
@ -2,6 +2,7 @@ const cors = require('../middleware/cors');
|
||||
const userMiddleware = require('../middleware/user');
|
||||
const allowQueryParams = require('../middleware/allow-query-params');
|
||||
const vectorError = require('../middleware/vector-error');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
const DataviewBackend = require('../backends/dataview');
|
||||
const AnalysisStatusBackend = require('../backends/analysis-status');
|
||||
const MapStoreMapConfigProvider = require('../models/mapconfig/provider/map-store-provider');
|
||||
@ -55,6 +56,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getTile(this.tileBackend, 'map_tile'),
|
||||
setCacheControlHeader(),
|
||||
@ -74,6 +76,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getTile(this.tileBackend, 'map_tile'),
|
||||
setCacheControlHeader(),
|
||||
@ -94,6 +97,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getTile(this.tileBackend, 'maplayer_tile'),
|
||||
setCacheControlHeader(),
|
||||
@ -113,6 +117,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getFeatureAttributes(this.attributesBackend),
|
||||
setCacheControlHeader(),
|
||||
@ -131,6 +136,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
allowQueryParams(['layer']),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat),
|
||||
getPreviewImageByCenter(this.previewBackend),
|
||||
setCacheControlHeader(),
|
||||
@ -147,6 +153,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
allowQueryParams(['layer']),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat),
|
||||
getPreviewImageByBoundingBox(this.previewBackend),
|
||||
setCacheControlHeader(),
|
||||
@ -181,6 +188,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getDataview(this.dataviewBackend),
|
||||
setCacheControlHeader(),
|
||||
@ -197,6 +205,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getDataview(this.dataviewBackend),
|
||||
setCacheControlHeader(),
|
||||
@ -213,6 +222,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
dataviewSearch(this.dataviewBackend),
|
||||
setCacheControlHeader(),
|
||||
@ -229,6 +239,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
dataviewSearch(this.dataviewBackend),
|
||||
setCacheControlHeader(),
|
||||
@ -244,6 +255,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
analysisNodeStatus(this.analysisStatusBackend),
|
||||
sendResponse()
|
||||
);
|
||||
|
@ -7,6 +7,7 @@ const ResourceLocator = require('../models/resource-locator');
|
||||
const cors = require('../middleware/cors');
|
||||
const userMiddleware = require('../middleware/user');
|
||||
const allowQueryParams = require('../middleware/allow-query-params');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
const NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
|
||||
const NamedMapMapConfigProvider = require('../models/mapconfig/provider/named-map-provider');
|
||||
const CreateLayergroupMapConfigProvider = require('../models/mapconfig/provider/create-layergroup-provider');
|
||||
@ -69,6 +70,7 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal
|
||||
userMiddleware(),
|
||||
allowQueryParams(['aggregation']),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
initProfiler(isTemplateInstantiation),
|
||||
checkJsonContentType(),
|
||||
this.getCreateMapMiddlewares(useTemplate),
|
||||
|
@ -1,6 +1,7 @@
|
||||
const NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
|
||||
const cors = require('../middleware/cors');
|
||||
const userMiddleware = require('../middleware/user');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
const allowQueryParams = require('../middleware/allow-query-params');
|
||||
const vectorError = require('../middleware/vector-error');
|
||||
|
||||
@ -28,7 +29,7 @@ function getRequestParams(locals) {
|
||||
}
|
||||
|
||||
function NamedMapsController(prepareContext, namedMapProviderCache, tileBackend, previewBackend,
|
||||
surrogateKeysCache, tablesExtentApi, metadataBackend) {
|
||||
surrogateKeysCache, tablesExtentApi, metadataBackend, pgConnection) {
|
||||
this.namedMapProviderCache = namedMapProviderCache;
|
||||
this.tileBackend = tileBackend;
|
||||
this.previewBackend = previewBackend;
|
||||
@ -36,6 +37,7 @@ function NamedMapsController(prepareContext, namedMapProviderCache, tileBackend,
|
||||
this.tablesExtentApi = tablesExtentApi;
|
||||
this.metadataBackend = metadataBackend;
|
||||
this.prepareContext = prepareContext;
|
||||
this.pgConnection = pgConnection;
|
||||
}
|
||||
|
||||
module.exports = NamedMapsController;
|
||||
@ -48,6 +50,7 @@ NamedMapsController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
getNamedMapProvider({
|
||||
namedMapProviderCache: this.namedMapProviderCache,
|
||||
label: 'NAMED_MAP_TILE'
|
||||
@ -72,6 +75,7 @@ NamedMapsController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
allowQueryParams(['layer', 'zoom', 'lon', 'lat', 'bbox']),
|
||||
this.prepareContext,
|
||||
dbConnSetup(this.pgConnection),
|
||||
getNamedMapProvider({
|
||||
namedMapProviderCache: this.namedMapProviderCache,
|
||||
label: 'STATIC_VIZ_MAP', forcedFormat: 'png'
|
||||
|
@ -3,15 +3,13 @@ const cleanUpQueryParams = require('./clean-up-query-params');
|
||||
const layergroupToken = require('./layergroup-token');
|
||||
const credentials = require('./credentials');
|
||||
const authorize = require('./authorize');
|
||||
const dbConnSetup = require('./db-conn-setup');
|
||||
|
||||
module.exports = function prepareContextMiddleware(authApi, pgConnection) {
|
||||
module.exports = function prepareContextMiddleware(authApi) {
|
||||
return [
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(authApi),
|
||||
dbConnSetup(pgConnection)
|
||||
authorize(authApi)
|
||||
];
|
||||
};
|
||||
|
@ -217,7 +217,7 @@ module.exports = function(serverOptions) {
|
||||
|
||||
const prepareContext = typeof serverOptions.req2params === 'function' ?
|
||||
serverOptions.req2params :
|
||||
prepareContextMiddleware(authApi, pgConnection);
|
||||
prepareContextMiddleware(authApi);
|
||||
|
||||
/*******************************************************************************************************************
|
||||
* Routing
|
||||
@ -256,12 +256,13 @@ module.exports = function(serverOptions) {
|
||||
previewBackend,
|
||||
surrogateKeysCache,
|
||||
tablesExtentApi,
|
||||
metadataBackend
|
||||
metadataBackend,
|
||||
pgConnection
|
||||
).register(app);
|
||||
|
||||
new controller.NamedMapsAdmin(authApi, templateMaps).register(app);
|
||||
|
||||
new controller.Analyses(prepareContext).register(app);
|
||||
new controller.Analyses(prepareContext, pgConnection).register(app);
|
||||
|
||||
new controller.ServerInfo(versions).register(app);
|
||||
|
||||
|
@ -9,7 +9,7 @@ var TemplateMaps = require('../../../lib/cartodb/backends/template_maps');
|
||||
|
||||
const cleanUpQueryParamsMiddleware = require('../../../lib/cartodb/middleware/context/clean-up-query-params');
|
||||
const authorizeMiddleware = require('../../../lib/cartodb/middleware/context/authorize');
|
||||
const dbConnSetupMiddleware = require('../../../lib/cartodb/middleware/context/db-conn-setup');
|
||||
const dbConnSetupMiddleware = require('../../../lib/cartodb/middleware/db-conn-setup');
|
||||
const credentialsMiddleware = require('../../../lib/cartodb/middleware/context/credentials');
|
||||
const localsMiddleware = require('../../../lib/cartodb/middleware/context/locals');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user