2015-07-09 02:51:36 +08:00
|
|
|
var windshaft = require('windshaft');
|
2015-07-08 22:08:38 +08:00
|
|
|
var HealthCheck = require('../monitoring/health_check');
|
|
|
|
|
|
|
|
var WELCOME_MSG = "This is the CartoDB Maps API, " +
|
|
|
|
"see the documentation at http://docs.cartodb.com/cartodb-platform/maps-api.html";
|
|
|
|
|
|
|
|
|
2015-07-09 02:51:36 +08:00
|
|
|
var versions = {
|
|
|
|
windshaft: windshaft.version,
|
|
|
|
grainstore: windshaft.grainstore.version(),
|
|
|
|
node_mapnik: windshaft.mapnik.version,
|
|
|
|
mapnik: windshaft.mapnik.versions.mapnik,
|
|
|
|
windshaft_cartodb: require('../../../package.json').version
|
|
|
|
};
|
|
|
|
|
|
|
|
function ServerInfoController() {
|
2015-07-08 22:08:38 +08:00
|
|
|
this.healthConfig = global.environment.health || {};
|
2015-09-04 19:21:54 +08:00
|
|
|
this.healthCheck = new HealthCheck(global.environment.disabled_file);
|
2015-07-08 22:08:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ServerInfoController;
|
|
|
|
|
|
|
|
ServerInfoController.prototype.register = function(app) {
|
|
|
|
app.get('/health', this.health.bind(this));
|
|
|
|
app.get('/', this.welcome.bind(this));
|
|
|
|
app.get('/version', this.version.bind(this));
|
|
|
|
};
|
|
|
|
|
|
|
|
ServerInfoController.prototype.welcome = function(req, res) {
|
2015-09-17 08:05:25 +08:00
|
|
|
res.status(200).send(WELCOME_MSG);
|
2015-07-08 22:08:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
ServerInfoController.prototype.version = function(req, res) {
|
2015-09-17 08:05:25 +08:00
|
|
|
res.status(200).send(versions);
|
2015-07-08 22:08:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
ServerInfoController.prototype.health = function(req, res) {
|
|
|
|
if (!!this.healthConfig.enabled) {
|
|
|
|
var startTime = Date.now();
|
2015-09-08 21:42:30 +08:00
|
|
|
this.healthCheck.check(function(err) {
|
2015-07-08 22:08:38 +08:00
|
|
|
var ok = !err;
|
|
|
|
var response = {
|
|
|
|
enabled: true,
|
|
|
|
ok: ok,
|
2015-09-04 19:21:54 +08:00
|
|
|
elapsed: Date.now() - startTime
|
2015-07-08 22:08:38 +08:00
|
|
|
};
|
|
|
|
if (err) {
|
|
|
|
response.err = err.message;
|
|
|
|
}
|
2015-09-17 08:05:25 +08:00
|
|
|
res.status(ok ? 200 : 503).send(response);
|
2015-07-08 22:08:38 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
} else {
|
2015-09-17 08:05:25 +08:00
|
|
|
res.status(200).send({enabled: false, ok: true});
|
2015-07-08 22:08:38 +08:00
|
|
|
}
|
|
|
|
};
|