Compose instantiate layergroup middleware

This commit is contained in:
Daniel García Aubert
2017-11-02 19:24:33 +01:00
parent 4607e4a12d
commit 717332d941
+55 -40
View File
@@ -50,46 +50,29 @@ module.exports = MapController;
MapController.prototype.register = function(app) {
app.get(app.base_url_mapconfig, this.composeCreateLayergroupMiddleware({
parseConfigQueryParam: true,
includeQuery: true,
parseConfigQueryParam: true
label: 'ANONYMOUS LAYERGROUP',
addContext: true
}));
app.post(app.base_url_mapconfig, this.composeCreateLayergroupMiddleware({
includeQuery: true
includeQuery: true,
label: 'ANONYMOUS LAYERGROUP',
addContext: true
}));
app.get(app.base_url_templated + '/:template_id/jsonp', this.composeInstantiateLayergroupMiddleware({
parseConfigQueryParam: true,
useTemplateHash: true,
label: 'NAMED MAP LAYERGROUP'
}));
app.post(app.base_url_templated + '/:template_id', this.composeInstantiateLayergroupMiddleware({
useTemplateHash: true,
label: 'NAMED MAP LAYERGROUP'
}));
app.get(
app.base_url_templated + '/:template_id/jsonp',
cors(),
userMiddleware,
this.prepareContext,
prepareJsonTemplateParams,
this.getTemplate.bind(this),
this.instantiateLayergroup.bind(this),
this.afterLayergroupCreateBuilder({
useTemplateHash: true
}),
sendResponse,
augmentError({
label: 'NAMED MAP LAYERGROUP'
})
);
app.post(
app.base_url_templated + '/:template_id',
cors(),
userMiddleware,
this.prepareContext,
prepareTemplateParams,
this.getTemplate.bind(this),
this.instantiateLayergroup.bind(this),
this.afterLayergroupCreateBuilder({
useTemplateHash: true
}),
sendResponse,
augmentError({
label: 'NAMED MAP LAYERGROUP'
})
);
app.options(app.base_url_mapconfig, cors('Content-Type'));
};
@@ -97,7 +80,9 @@ MapController.prototype.composeCreateLayergroupMiddleware = function (options) {
const {
parseConfigQueryParam = false,
useTemplateHash = false,
includeQuery = false
includeQuery = false,
label,
addContext = false
} = options;
return [
@@ -120,15 +105,45 @@ MapController.prototype.composeCreateLayergroupMiddleware = function (options) {
this.setTurboCartoMetadataToLayergroup.bind(this),
this.setSurrogateKeyHeader.bind(this),
sendResponse,
augmentError({
label: 'ANONYMOUS LAYERGROUP',
addContext: true
})
augmentError({ label, addContext })
];
};
MapController.prototype.composeInstantiateLayergroupMiddleware = function (options) {
const {
parseConfigQueryParam = false,
useTemplateHash = false,
includeQuery = false,
label,
addContext = false
} = options;
return [
cors(),
userMiddleware,
this.prepareContext,
parseConfigQueryParam ? prepareJsonTemplateParams : prepareTemplateParams,
this.getTemplate.bind(this),
this.instantiateLayergroup.bind(this),
this.incrementMapViewCount.bind(this),
this.augmentLayergroupData.bind(this),
this.getAffectedTables.bind(this),
this.setCacheChannel.bind(this),
this.setLastUpdatedTimeToLayergroup.bind(this),
this.setCacheControl.bind(this),
this.setLayerStats.bind(this),
this.setLayergroupIdHeaderBuilder(useTemplateHash),
this.setDataviewsAndWidgetsUrlsToLayergroupMetadata.bind(this),
this.setAnalysesMetadataToLayergroupBuilder(includeQuery),
this.setTurboCartoMetadataToLayergroup.bind(this),
this.setSurrogateKeyHeader.bind(this),
sendResponse,
augmentError({ label, addContext })
];
};
function createGetPrepareConfig (req, res, next) {
req.profiler.start(`windshaft.createmap_${req.method.toLowecase}`);
req.profiler.start(`windshaft.createmap_get`);
const { config } = res.locals;