From 158f28c8e748a42cddd12934c0acd014ad1a6bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 1 Oct 2019 11:11:19 +0200 Subject: [PATCH] ES6 class and middlewares for version controller --- app/controllers/version_controller.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/controllers/version_controller.js b/app/controllers/version_controller.js index 853ff891..03c99ba9 100644 --- a/app/controllers/version_controller.js +++ b/app/controllers/version_controller.js @@ -1,18 +1,17 @@ 'use strict'; -var version = { - cartodb_sql_api: require(__dirname + '/../../package.json').version +const versions = { + cartodb_sql_api: require('./../../package.json').version }; -function VersionController() { +module.exports = class VersionController { + route (app) { + app.get(`${global.settings.base_url}/version`, version()); + } +}; + +function version () { + return function versionMiddleware (req, res) { + res.send(versions); + }; } - -VersionController.prototype.route = function (app) { - app.get(global.settings.base_url + '/version', this.handleVersion.bind(this)); -}; - -VersionController.prototype.handleVersion = function (req, res) { - res.send(version); -}; - -module.exports = VersionController;