Merge paths to perform the same middleware stack

This commit is contained in:
Daniel García Aubert
2018-04-18 19:07:38 +02:00
parent 56495522b8
commit 9bd9503e9b

View File

@@ -45,8 +45,11 @@ module.exports = class TileLayergroupController {
// REGEXP doesn't match with `val`
const not = (val) => `(?!${val})([^\/]+?)`;
mapRouter.get(
[ `/:token/:z/:x/:y@:scale_factor?x.:format`, `/:token/:z/:x/:y.:format` ],
mapRouter.get([
`/:token/:z/:x/:y@:scale_factor?x.:format`,
`/:token/:z/:x/:y.:format`,
`/:token${not('static')}/:layer/:z/:x/:y.(:format)`
],
layergroupToken(),
coordinates(),
credentials(),
@@ -60,33 +63,7 @@ module.exports = class TileLayergroupController {
this.pgConnection,
this.layergroupAffectedTablesCache
),
getTile(this.tileBackend, 'map_tile'),
cacheControlHeader(),
cacheChannelHeader(),
surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }),
lastModifiedHeader(),
incrementSuccessMetrics(global.statsClient),
incrementErrorMetrics(global.statsClient),
tileError(),
vectorError()
);
mapRouter.get(
`/:token${not('static')}/:layer/:z/:x/:y.(:format)`,
layergroupToken(),
coordinates(),
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.TILE),
cleanUpQueryParams(),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
getTile(this.tileBackend, 'maplayer_tile'),
getTile(this.tileBackend),
cacheControlHeader(),
cacheChannelHeader(),
surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }),
@@ -108,9 +85,9 @@ function getStatusCode(tile, format){
return tile.length === 0 && format === 'mvt' ? 204 : 200;
}
function getTile (tileBackend, profileLabel = 'tile') {
function getTile (tileBackend) {
return function getTileMiddleware (req, res, next) {
req.profiler.start(`windshaft.${profileLabel}`);
req.profiler.start(`windshaft.${req.params.layer ? 'maplayer_tile' : 'map_tile'}`);
const { mapConfigProvider } = res.locals;
const { token } = res.locals;