Unify layer and tile middlewares
This commit is contained in:
@@ -48,7 +48,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getTile(this.tileBackend),
|
||||
getTile(this.tileBackend, 'map_tile'),
|
||||
setCacheControlHeader(),
|
||||
setLastModifiedHeader(),
|
||||
getAffectedTables(this.layergroupAffectedTables, this.pgConnection),
|
||||
@@ -67,7 +67,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
getTile(this.tileBackend),
|
||||
getTile(this.tileBackend, 'map_tile'),
|
||||
setCacheControlHeader(),
|
||||
setLastModifiedHeader(),
|
||||
getAffectedTables(this.layergroupAffectedTables, this.pgConnection),
|
||||
@@ -87,7 +87,7 @@ LayergroupController.prototype.register = function(app) {
|
||||
userMiddleware(),
|
||||
this.prepareContext,
|
||||
getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
|
||||
layer(this.tileBackend),
|
||||
getTile(this.tileBackend, 'maplayer_tile'),
|
||||
setCacheControlHeader(),
|
||||
setLastModifiedHeader(),
|
||||
getAffectedTables(this.layergroupAffectedTables, this.pgConnection),
|
||||
@@ -394,37 +394,9 @@ function parseFormat (format = '') {
|
||||
return formatStat;
|
||||
}
|
||||
|
||||
function getTile (tileBackend) {
|
||||
return function tileMiddleware (req, res, next) {
|
||||
req.profiler.start('windshaft.map_tile');
|
||||
|
||||
const { mapConfigProvider } = res.locals;
|
||||
const params = getRequestParams(res.locals);
|
||||
|
||||
tileBackend.getTile(mapConfigProvider, params, (err, tile, headers, stats = {}) => {
|
||||
req.profiler.add(stats);
|
||||
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (headers) {
|
||||
res.set(headers);
|
||||
}
|
||||
|
||||
const formatStat = parseFormat(req.params.format);
|
||||
|
||||
res.statusCode = getStatusCode(tile, formatStat);
|
||||
res.body = tile;
|
||||
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function layer (tileBackend) {
|
||||
return function layerMiddleware (req, res, next) {
|
||||
req.profiler.start('windshaft.maplayer_tile');
|
||||
function getTile (tileBackend, profileLabel = 'tile') {
|
||||
return function getTileMiddleware (req, res, next) {
|
||||
req.profiler.start(`windshaft.${profileLabel}`);
|
||||
|
||||
const { mapConfigProvider } = res.locals;
|
||||
const params = getRequestParams(res.locals);
|
||||
@@ -647,7 +619,7 @@ function incrementErrorMetrics (statsClient) {
|
||||
|
||||
next(err);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function tileError () {
|
||||
return function tileErrorMiddleware (err, req, res, next) {
|
||||
|
||||
Reference in New Issue
Block a user