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