Use express router to group controllers' enpoints and reuse common middleware for named maps admin controller

This commit is contained in:
Daniel García Aubert
2017-09-22 16:45:34 +02:00
parent ee8619c470
commit 0bdeee64a7
2 changed files with 16 additions and 10 deletions
+13 -7
View File
@@ -26,13 +26,19 @@ util.inherits(NamedMapsAdminController, BaseController);
module.exports = NamedMapsAdminController;
NamedMapsAdminController.prototype.register = function(app) {
app.post(app.base_url_templated, cors(), userMiddleware, this.create.bind(this));
app.put(app.base_url_templated + '/:template_id', cors(), userMiddleware, this.update.bind(this));
app.get(app.base_url_templated + '/:template_id', cors(), userMiddleware, this.retrieve.bind(this));
app.delete(app.base_url_templated + '/:template_id', cors(), userMiddleware, this.destroy.bind(this));
app.get(app.base_url_templated, cors(), userMiddleware, this.list.bind(this));
app.options(app.base_url_templated + '/:template_id', cors('Content-Type'));
NamedMapsAdminController.prototype.register = function (router) {
router.options('/:template_id', cors('Content-Type'));
router.use(
cors(),
userMiddleware
);
router.post('/', this.create.bind(this));
router.put('/:template_id', this.update.bind(this));
router.get('/:template_id', this.retrieve.bind(this));
router.delete('/:template_id', this.destroy.bind(this));
router.get('/', this.list.bind(this));
};
NamedMapsAdminController.prototype.create = function(req, res, next) {
+3 -3
View File
@@ -253,12 +253,12 @@ module.exports = function(serverOptions) {
metadataBackend
).register(app);
new controller.NamedMapsAdmin(authApi, pgConnection, templateMaps).register(app);
const namedMapsAdminRouter = express.Router();
new controller.NamedMapsAdmin(authApi, pgConnection, templateMaps).register(namedMapsAdminRouter);
app.use(app.base_url_templated, namedMapsAdminRouter);
const analysisRouter = express.Router();
new controller.Analyses(authApi, pgConnection).register(analysisRouter);
app.use(app.base_url_mapconfig, analysisRouter);
new controller.ServerInfo(versions).register(app);