Extract rest of the middlewares from prepare contex
This commit is contained in:
parent
30dab7df9f
commit
7ff7b0c2d1
@ -1,11 +1,14 @@
|
||||
var PSQL = require('cartodb-psql');
|
||||
var cors = require('../middleware/cors');
|
||||
var userMiddleware = require('../middleware/user');
|
||||
const locals = require('../middleware/locals');
|
||||
const cleanUpQueryParams = require('../middleware/clean-up-query-params');
|
||||
const layergroupToken = require('../middleware/layergroup-token');
|
||||
const credentials = require('../middleware/credentials');
|
||||
const authorize = require('../middleware/authorize');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
|
||||
function AnalysesController(prepareContext, pgConnection, authApi) {
|
||||
this.prepareContext = prepareContext;
|
||||
function AnalysesController(pgConnection, authApi) {
|
||||
this.pgConnection = pgConnection;
|
||||
this.authApi = authApi;
|
||||
}
|
||||
@ -17,7 +20,10 @@ AnalysesController.prototype.register = function (app) {
|
||||
`${app.base_url_mapconfig}/analyses/catalog`,
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createPGClient(),
|
||||
|
@ -2,6 +2,10 @@ const cors = require('../middleware/cors');
|
||||
const userMiddleware = require('../middleware/user');
|
||||
const allowQueryParams = require('../middleware/allow-query-params');
|
||||
const vectorError = require('../middleware/vector-error');
|
||||
const locals = require('../middleware/locals');
|
||||
const cleanUpQueryParams = require('../middleware/clean-up-query-params');
|
||||
const layergroupToken = require('../middleware/layergroup-token');
|
||||
const credentials = require('../middleware/credentials');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
const authorize = require('../middleware/authorize');
|
||||
const DataviewBackend = require('../backends/dataview');
|
||||
@ -30,7 +34,7 @@ const SUPPORTED_FORMATS = {
|
||||
* @param {AnalysisBackend} analysisBackend
|
||||
* @constructor
|
||||
*/
|
||||
function LayergroupController(prepareContext, pgConnection, mapStore, tileBackend, previewBackend, attributesBackend,
|
||||
function LayergroupController(pgConnection, mapStore, tileBackend, previewBackend, attributesBackend,
|
||||
surrogateKeysCache, userLimitsApi, layergroupAffectedTables, analysisBackend, authApi) {
|
||||
this.pgConnection = pgConnection;
|
||||
this.mapStore = mapStore;
|
||||
@ -43,8 +47,6 @@ function LayergroupController(prepareContext, pgConnection, mapStore, tileBacken
|
||||
|
||||
this.dataviewBackend = new DataviewBackend(analysisBackend);
|
||||
this.analysisStatusBackend = new AnalysisStatusBackend();
|
||||
|
||||
this.prepareContext = prepareContext;
|
||||
this.authApi = authApi;
|
||||
}
|
||||
|
||||
@ -57,7 +59,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
`${basePath}/:token/:z/:x/:y@:scale_factor?x.:format`,
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -78,7 +83,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
`${basePath}/:token/:z/:x/:y.:format`,
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -100,7 +108,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
distinguishLayergroupFromStaticRoute(),
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -121,7 +132,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
`${basePath}/:token/:layer/attributes/:fid`,
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -141,7 +155,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(['layer']),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat),
|
||||
@ -159,7 +176,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(['layer']),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat),
|
||||
@ -195,7 +215,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -213,7 +236,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -231,7 +257,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -249,7 +278,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(allowedDataviewQueryParams),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
createMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
@ -266,7 +298,10 @@ LayergroupController.prototype.register = function(app) {
|
||||
`${basePath}/:token/analysis/node/:nodeId`,
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
analysisNodeStatus(this.analysisStatusBackend),
|
||||
|
@ -7,6 +7,10 @@ const ResourceLocator = require('../models/resource-locator');
|
||||
const cors = require('../middleware/cors');
|
||||
const userMiddleware = require('../middleware/user');
|
||||
const allowQueryParams = require('../middleware/allow-query-params');
|
||||
const locals = require('../middleware/locals');
|
||||
const cleanUpQueryParams = require('../middleware/clean-up-query-params');
|
||||
const layergroupToken = require('../middleware/layergroup-token');
|
||||
const credentials = require('../middleware/credentials');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
const authorize = require('../middleware/authorize');
|
||||
const NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
|
||||
@ -27,7 +31,7 @@ const LayergroupMetadata = require('../utils/layergroup-metadata');
|
||||
* @param {StatsBackend} statsBackend
|
||||
* @constructor
|
||||
*/
|
||||
function MapController(prepareContext, pgConnection, templateMaps, mapBackend, metadataBackend,
|
||||
function MapController(pgConnection, templateMaps, mapBackend, metadataBackend,
|
||||
surrogateKeysCache, userLimitsApi, layergroupAffectedTables, mapConfigAdapter,
|
||||
statsBackend, authApi) {
|
||||
this.pgConnection = pgConnection;
|
||||
@ -43,7 +47,6 @@ function MapController(prepareContext, pgConnection, templateMaps, mapBackend, m
|
||||
this.layergroupMetadata = new LayergroupMetadata(resourceLocator);
|
||||
|
||||
this.statsBackend = statsBackend;
|
||||
this.prepareContext = prepareContext;
|
||||
this.authApi = authApi;
|
||||
}
|
||||
|
||||
@ -71,7 +74,10 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(['aggregation']),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
initProfiler(isTemplateInstantiation),
|
||||
|
@ -1,6 +1,10 @@
|
||||
const NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
|
||||
const cors = require('../middleware/cors');
|
||||
const userMiddleware = require('../middleware/user');
|
||||
const locals = require('../middleware/locals');
|
||||
const cleanUpQueryParams = require('../middleware/clean-up-query-params');
|
||||
const layergroupToken = require('../middleware/layergroup-token');
|
||||
const credentials = require('../middleware/credentials');
|
||||
const dbConnSetup = require('../middleware/db-conn-setup');
|
||||
const authorize = require('../middleware/authorize');
|
||||
const allowQueryParams = require('../middleware/allow-query-params');
|
||||
@ -29,7 +33,7 @@ function getRequestParams(locals) {
|
||||
return params;
|
||||
}
|
||||
|
||||
function NamedMapsController(prepareContext, namedMapProviderCache, tileBackend, previewBackend,
|
||||
function NamedMapsController(namedMapProviderCache, tileBackend, previewBackend,
|
||||
surrogateKeysCache, tablesExtentApi, metadataBackend, pgConnection, authApi) {
|
||||
this.namedMapProviderCache = namedMapProviderCache;
|
||||
this.tileBackend = tileBackend;
|
||||
@ -37,7 +41,6 @@ function NamedMapsController(prepareContext, namedMapProviderCache, tileBackend,
|
||||
this.surrogateKeysCache = surrogateKeysCache;
|
||||
this.tablesExtentApi = tablesExtentApi;
|
||||
this.metadataBackend = metadataBackend;
|
||||
this.prepareContext = prepareContext;
|
||||
this.pgConnection = pgConnection;
|
||||
this.authApi = authApi;
|
||||
}
|
||||
@ -51,7 +54,10 @@ NamedMapsController.prototype.register = function(app) {
|
||||
`${base_url_templated}/:template_id/:layer/:z/:x/:y.(:format)`,
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
getNamedMapProvider({
|
||||
@ -77,7 +83,10 @@ NamedMapsController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware(),
|
||||
allowQueryParams(['layer', 'zoom', 'lon', 'lat', 'bbox']),
|
||||
this.prepareContext,
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
authorize(this.authApi),
|
||||
dbConnSetup(this.pgConnection),
|
||||
getNamedMapProvider({
|
||||
|
@ -1,8 +1,8 @@
|
||||
const { templateName } = require('../backends/template_maps');
|
||||
const cors = require('../middleware/cors');
|
||||
const userMiddleware = require('../middleware/user');
|
||||
const localsMiddleware = require('../middleware/context/locals');
|
||||
const credentialsMiddleware = require('../middleware/context/credentials');
|
||||
const localsMiddleware = require('../middleware/locals');
|
||||
const credentialsMiddleware = require('../middleware/credentials');
|
||||
|
||||
/**
|
||||
* @param {AuthApi} authApi
|
||||
|
@ -1,13 +0,0 @@
|
||||
const locals = require('./locals');
|
||||
const cleanUpQueryParams = require('./clean-up-query-params');
|
||||
const layergroupToken = require('./layergroup-token');
|
||||
const credentials = require('./credentials');
|
||||
|
||||
module.exports = function prepareContextMiddleware() {
|
||||
return [
|
||||
locals(),
|
||||
cleanUpQueryParams(),
|
||||
layergroupToken(),
|
||||
credentials(),
|
||||
];
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
const LayergroupToken = require('../../models/layergroup-token');
|
||||
const LayergroupToken = require('../models/layergroup-token');
|
||||
const authErrorMessageTemplate = function (signer, user) {
|
||||
return `Cannot use map signature of user "${signer}" on db of user "${user}"`;
|
||||
};
|
@ -49,8 +49,6 @@ 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);
|
||||
@ -215,16 +213,11 @@ module.exports = function(serverOptions) {
|
||||
|
||||
var versions = getAndValidateVersions(serverOptions);
|
||||
|
||||
const prepareContext = typeof serverOptions.req2params === 'function' ?
|
||||
serverOptions.req2params :
|
||||
prepareContextMiddleware();
|
||||
|
||||
/*******************************************************************************************************************
|
||||
* Routing
|
||||
******************************************************************************************************************/
|
||||
|
||||
new controller.Layergroup(
|
||||
prepareContext,
|
||||
pgConnection,
|
||||
mapStore,
|
||||
tileBackend,
|
||||
@ -238,7 +231,6 @@ module.exports = function(serverOptions) {
|
||||
).register(app);
|
||||
|
||||
new controller.Map(
|
||||
prepareContext,
|
||||
pgConnection,
|
||||
templateMaps,
|
||||
mapBackend,
|
||||
@ -252,7 +244,6 @@ module.exports = function(serverOptions) {
|
||||
).register(app);
|
||||
|
||||
new controller.NamedMaps(
|
||||
prepareContext,
|
||||
namedMapProviderCache,
|
||||
tileBackend,
|
||||
previewBackend,
|
||||
@ -265,7 +256,7 @@ module.exports = function(serverOptions) {
|
||||
|
||||
new controller.NamedMapsAdmin(authApi, templateMaps).register(app);
|
||||
|
||||
new controller.Analyses(prepareContext, pgConnection, authApi).register(app);
|
||||
new controller.Analyses(pgConnection, authApi).register(app);
|
||||
|
||||
new controller.ServerInfo(versions).register(app);
|
||||
|
||||
|
@ -7,11 +7,11 @@ var PgConnection = require('../../../lib/cartodb/backends/pg_connection');
|
||||
var AuthApi = require('../../../lib/cartodb/api/auth_api');
|
||||
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/clean-up-query-params');
|
||||
const authorizeMiddleware = require('../../../lib/cartodb/middleware/authorize');
|
||||
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');
|
||||
const credentialsMiddleware = require('../../../lib/cartodb/middleware/credentials');
|
||||
const localsMiddleware = require('../../../lib/cartodb/middleware/locals');
|
||||
|
||||
var windshaft = require('windshaft');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user