Reorder middlewares to optimize workflow

This commit is contained in:
Daniel García Aubert 2018-03-16 16:12:36 +01:00
parent 67d2d2fe95
commit 639a69a639
7 changed files with 36 additions and 39 deletions

View File

@ -21,9 +21,9 @@ AnalysesController.prototype.register = function (app) {
app.get(
`${mapconfigBasePath}/analyses/catalog`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),

View File

@ -57,9 +57,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/:z/:x/:y@:scale_factor?x.:format`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -81,9 +81,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/:z/:x/:y.:format`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -106,9 +106,9 @@ LayergroupController.prototype.register = function(app) {
`${mapconfigBasePath}/:token/:layer/:z/:x/:y.(:format)`,
distinguishLayergroupFromStaticRoute(),
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -130,9 +130,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/:layer/attributes/:fid`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -152,9 +152,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/static/center/:token/:z/:lat/:lng/:width/:height.:format`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(['layer']),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -172,9 +172,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/static/bbox/:token/:west,:south,:east,:north/:width/:height.:format`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(['layer']),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -210,9 +210,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/dataview/:dataviewName`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(allowedDataviewQueryParams),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -230,9 +230,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/:layer/widget/:dataviewName`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(allowedDataviewQueryParams),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -250,9 +250,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/dataview/:dataviewName/search`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(allowedDataviewQueryParams),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -270,9 +270,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/:layer/widget/:dataviewName/search`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(allowedDataviewQueryParams),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -290,9 +290,9 @@ LayergroupController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/:token/analysis/node/:nodeId`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),

View File

@ -73,9 +73,9 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal
return [
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(['aggregation']),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),

View File

@ -52,9 +52,9 @@ NamedMapsController.prototype.register = function(app) {
app.get(
`${templateBasePath}/:template_id/:layer/:z/:x/:y.(:format)`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),
@ -80,9 +80,9 @@ NamedMapsController.prototype.register = function(app) {
app.get(
`${mapconfigBasePath}/static/named/:template_id/:width/:height.:format`,
cors(),
userMiddleware(),
locals(),
cleanUpQueryParams(['layer', 'zoom', 'lon', 'lat', 'bbox']),
locals(),
userMiddleware(),
layergroupToken(),
credentials(),
authorize(this.authApi),

View File

@ -23,8 +23,8 @@ NamedMapsAdminController.prototype.register = function (app) {
app.post(
`${templateBasePath}/`,
cors(),
userMiddleware(),
localsMiddleware(),
userMiddleware(),
credentialsMiddleware(),
checkContentType({ action: 'POST', label: 'POST TEMPLATE' }),
authorizedByAPIKey({ authApi: this.authApi, action: 'create', label: 'POST TEMPLATE' }),
@ -35,8 +35,8 @@ NamedMapsAdminController.prototype.register = function (app) {
app.put(
`${templateBasePath}/:template_id`,
cors(),
userMiddleware(),
localsMiddleware(),
userMiddleware(),
credentialsMiddleware(),
checkContentType({ action: 'PUT', label: 'PUT TEMPLATE' }),
authorizedByAPIKey({ authApi: this.authApi, action: 'update', label: 'PUT TEMPLATE' }),
@ -47,8 +47,8 @@ NamedMapsAdminController.prototype.register = function (app) {
app.get(
`${templateBasePath}/:template_id`,
cors(),
userMiddleware(),
localsMiddleware(),
userMiddleware(),
credentialsMiddleware(),
authorizedByAPIKey({ authApi: this.authApi, action: 'get', label: 'GET TEMPLATE' }),
retrieveTemplate({ templateMaps: this.templateMaps }),
@ -58,8 +58,8 @@ NamedMapsAdminController.prototype.register = function (app) {
app.delete(
`${templateBasePath}/:template_id`,
cors(),
userMiddleware(),
localsMiddleware(),
userMiddleware(),
credentialsMiddleware(),
authorizedByAPIKey({ authApi: this.authApi, action: 'delete', label: 'DELETE TEMPLATE' }),
destroyTemplate({ templateMaps: this.templateMaps }),
@ -69,8 +69,8 @@ NamedMapsAdminController.prototype.register = function (app) {
app.get(
`${templateBasePath}/`,
cors(),
userMiddleware(),
localsMiddleware(),
userMiddleware(),
credentialsMiddleware(),
authorizedByAPIKey({ authApi: this.authApi, action: 'list', label: 'GET TEMPLATE LIST' }),
listTemplates({ templateMaps: this.templateMaps }),

View File

@ -24,9 +24,6 @@ module.exports = function cleanUpQueryParamsMiddleware (customQueryParams = [])
req.query = _.pick(req.query, allowedQueryParams);
// bring all query values onto res.locals object
_.extend(res.locals, req.query);
next();
};
};

View File

@ -1,6 +1,6 @@
module.exports = function locals () {
return function localsMiddleware (req, res, next) {
res.locals = Object.assign(req.params || {}, res.locals);
res.locals = Object.assign({}, req.query, req.params);
next();
};