ES6 class and middlewares for version controller

This commit is contained in:
Daniel García Aubert 2019-10-01 11:11:19 +02:00
parent ab9a7fd2fa
commit 158f28c8e7

View File

@ -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;