Create .middlewares() method to be mounted in dataview controller

This commit is contained in:
Daniel García Aubert 2018-05-11 13:20:05 +02:00
parent 1bc017eac9
commit a77dd9a11f

View File

@ -5,6 +5,7 @@ const dbConnSetup = require('../middlewares/db-conn-setup');
const authorize = require('../middlewares/authorize');
const rateLimit = require('../middlewares/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
const { DATAVIEW: DATAVIEW_GROUP, DATAVIEW_SEARCH: DATAVIEW_SEARCH_GROUP } = RATE_LIMIT_ENDPOINTS_GROUPS;
const createMapStoreMapConfigProvider = require('../middlewares/map-store-map-config-provider');
const cacheControlHeader = require('../middlewares/cache-control-header');
const cacheChannelHeader = require('../middlewares/cache-channel-header');
@ -49,34 +50,19 @@ module.exports = class DataviewLayergroupController {
// Undocumented/non-supported API endpoint methods.
// Use at your own peril.
mapRouter.get(
`/:token/dataview/:dataviewName`,
layergroupToken(),
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
getDataview(this.dataviewBackend),
cacheControlHeader(),
cacheChannelHeader(),
surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }),
lastModifiedHeader()
);
mapRouter.get('/:token/dataview/:dataviewName', this.middlewares('get', DATAVIEW_GROUP));
mapRouter.get('/:token/:layer/widget/:dataviewName', this.middlewares('get', DATAVIEW_GROUP));
mapRouter.get('/:token/dataview/:dataviewName/search', this.middlewares('search', DATAVIEW_SEARCH_GROUP));
mapRouter.get('/:token/:layer/widget/:dataviewName/search', this.middlewares('search', DATAVIEW_SEARCH_GROUP));
}
mapRouter.get(
`/:token/:layer/widget/:dataviewName`,
middlewares ({ action, rateLimitGroup }) {
return [
layergroupToken(),
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW),
rateLimit(this.userLimitsBackend, rateLimitGroup),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
@ -84,54 +70,12 @@ module.exports = class DataviewLayergroupController {
this.pgConnection,
this.layergroupAffectedTablesCache
),
getDataview(this.dataviewBackend),
action === 'search' ? dataviewSearch(this.dataviewBackend) : getDataview(this.dataviewBackend),
cacheControlHeader(),
cacheChannelHeader(),
surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }),
lastModifiedHeader()
);
mapRouter.get(
`/:token/dataview/:dataviewName/search`,
layergroupToken(),
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW_SEARCH),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
dataviewSearch(this.dataviewBackend),
cacheControlHeader(),
cacheChannelHeader(),
surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }),
lastModifiedHeader()
);
mapRouter.get(
`/:token/:layer/widget/:dataviewName/search`,
layergroupToken(),
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW_SEARCH),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
dataviewSearch(this.dataviewBackend),
cacheControlHeader(),
cacheChannelHeader(),
surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }),
lastModifiedHeader()
);
];
}
};