Now that mapConfigProvider is linked to 'res.locals' do not pass the whole 'res.locals' to map-config-provider to avoid converting circular structure to JSON
This commit is contained in:
@@ -83,13 +83,15 @@ LayergroupController.prototype.register = function(app) {
|
||||
this.attributes(this.attributesBackend)
|
||||
);
|
||||
|
||||
const forcedFormat = 'png';
|
||||
|
||||
app.get(
|
||||
app.base_url_mapconfig + '/static/center/:token/:z/:lat/:lng/:width/:height.:format',
|
||||
cors(),
|
||||
userMiddleware,
|
||||
allowQueryParams(['layer']),
|
||||
this.prepareContext,
|
||||
this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat),
|
||||
this.center(this.previewBackend)
|
||||
);
|
||||
|
||||
@@ -99,7 +101,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware,
|
||||
allowQueryParams(['layer']),
|
||||
this.prepareContext,
|
||||
this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi, forcedFormat),
|
||||
this.bbox(this.previewBackend)
|
||||
);
|
||||
|
||||
@@ -188,11 +190,27 @@ LayergroupController.prototype.analysisNodeStatus = function (analysisStatusBack
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
LayergroupController.prototype.getMapStoreMapConfigProvider = function (mapStore, userLimitsApi) {
|
||||
function getRequestParams(locals) {
|
||||
const params = Object.assign({}, locals);
|
||||
|
||||
delete params.mapConfigProvider;
|
||||
delete params.allowedQueryParams;
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
LayergroupController.prototype.getMapStoreMapConfigProvider = function (mapStore, userLimitsApi, forcedFormat = null) {
|
||||
return function getMapStoreMapConfigProviderMiddleware (req, res, next) {
|
||||
const { user } = res.locals;
|
||||
|
||||
res.locals.mapConfigProvider = new MapStoreMapConfigProvider(mapStore, user, userLimitsApi, res.locals);
|
||||
const params = getRequestParams(res.locals);
|
||||
|
||||
if (forcedFormat) {
|
||||
params.format = forcedFormat;
|
||||
params.layer = params.layer || 'all';
|
||||
}
|
||||
|
||||
res.locals.mapConfigProvider = new MapStoreMapConfigProvider(mapStore, user, userLimitsApi, params);
|
||||
|
||||
next();
|
||||
};
|
||||
@@ -338,12 +356,6 @@ LayergroupController.prototype.center = function (previewBackend) {
|
||||
};
|
||||
|
||||
const format = req.params.format === 'jpg' ? 'jpeg' : 'png';
|
||||
|
||||
// We force always the tile to be generated using PNG because
|
||||
// is the only format we support by now
|
||||
res.locals.format = 'png';
|
||||
res.locals.layer = res.locals.layer || 'all';
|
||||
|
||||
const { mapConfigProvider } = res.locals;
|
||||
|
||||
previewBackend.getImage(mapConfigProvider, format, width, height, zoom, center,(err, image, headers, stats) => {
|
||||
@@ -371,14 +383,7 @@ LayergroupController.prototype.bbox = function (previewBackend) {
|
||||
east: +req.params.east,
|
||||
south: +req.params.south
|
||||
};
|
||||
|
||||
const format = req.params.format === 'jpg' ? 'jpeg' : 'png';
|
||||
|
||||
// We force always the tile to be generated using PNG because
|
||||
// is the only format we support by now
|
||||
res.locals.format = 'png';
|
||||
res.locals.layer = res.locals.layer || 'all';
|
||||
|
||||
const { mapConfigProvider } = res.locals;
|
||||
|
||||
previewBackend.getImage(mapConfigProvider, format, width, height, bounds, (err, image, headers, stats) => {
|
||||
|
||||
Reference in New Issue
Block a user