adding rate limit middlewware to maps controller

This commit is contained in:
Simon Martín 2018-02-20 11:26:09 +01:00
parent 06ec3f80b9
commit e061b3e631

View File

@ -7,6 +7,7 @@ var ResourceLocator = require('../models/resource-locator');
var cors = require('../middleware/cors');
var userMiddleware = require('../middleware/user');
const allowQueryParams = require('../middleware/allow-query-params');
const { rateLimitMiddleware, RATE_LIMIT_ENDPOINTS_GROUPS } = require('../middleware/rate-limit');
var MapConfig = windshaft.model.MapConfig;
var Datasource = windshaft.model.Datasource;
@ -53,11 +54,38 @@ MapController.prototype.register = function(app) {
const { base_url_mapconfig, base_url_templated } = app;
const useTemplate = true;
app.get(base_url_mapconfig, this.composeCreateMapMiddleware());
app.post(base_url_mapconfig, this.composeCreateMapMiddleware());
app.get(`${base_url_templated}/:template_id/jsonp`, this.composeCreateMapMiddleware(useTemplate));
app.post(`${base_url_templated}/:template_id`, this.composeCreateMapMiddleware(useTemplate));
app.options(app.base_url_mapconfig, cors('Content-Type'));
app.get(
base_url_mapconfig,
cors(),
userMiddleware,
rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_1),
this.composeCreateMapMiddleware()
);
app.post(
base_url_mapconfig,
cors(),
userMiddleware,
rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_1),
this.composeCreateMapMiddleware()
);
app.get(
`${base_url_templated}/:template_id/jsonp`,
cors(),
userMiddleware,
rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_13),
this.composeCreateMapMiddleware(useTemplate)
);
app.post(
`${base_url_templated}/:template_id`,
cors(),
userMiddleware,
rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_13),
this.composeCreateMapMiddleware(useTemplate)
);
app.options(
app.base_url_mapconfig,
cors('Content-Type')
);
};
MapController.prototype.composeCreateMapMiddleware = function (useTemplate = false) {
@ -68,8 +96,6 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal
const addContext = !useTemplate;
return [
cors(),
userMiddleware,
allowQueryParams(['aggregation']),
this.prepareContext,
this.initProfiler(isTemplateInstantiation),