Move server info to its own controller
This commit is contained in:
parent
1737cbe1a5
commit
c8568b175b
49
lib/cartodb/controllers/server_info.js
Normal file
49
lib/cartodb/controllers/server_info.js
Normal file
@ -0,0 +1,49 @@
|
||||
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";
|
||||
|
||||
function ServerInfoController(versions) {
|
||||
this.versions = versions || {};
|
||||
|
||||
this.healthConfig = global.environment.health || {};
|
||||
this.healthCheck = new HealthCheck();
|
||||
}
|
||||
|
||||
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) {
|
||||
res.send(WELCOME_MSG, 200);
|
||||
};
|
||||
|
||||
ServerInfoController.prototype.version = function(req, res) {
|
||||
res.send(this.versions, 200);
|
||||
};
|
||||
|
||||
ServerInfoController.prototype.health = function(req, res) {
|
||||
if (!!this.healthConfig.enabled) {
|
||||
var startTime = Date.now();
|
||||
this.healthCheck.check(this.healthConfig, function(err, result) {
|
||||
var ok = !err;
|
||||
var response = {
|
||||
enabled: true,
|
||||
ok: ok,
|
||||
elapsed: Date.now() - startTime,
|
||||
result: result
|
||||
};
|
||||
if (err) {
|
||||
response.err = err.message;
|
||||
}
|
||||
res.send(response, ok ? 200 : 503);
|
||||
|
||||
});
|
||||
} else {
|
||||
res.send({enabled: false, ok: true}, 200);
|
||||
}
|
||||
};
|
@ -6,8 +6,6 @@ var cartodbRedis = require('cartodb-redis');
|
||||
var _ = require('underscore');
|
||||
var step = require('step');
|
||||
|
||||
|
||||
var HealthCheck = require('./monitoring/health_check');
|
||||
var StaticMapsController = require('./controllers/static_maps');
|
||||
var MapController = require('./controllers/map');
|
||||
|
||||
@ -43,16 +41,10 @@ var REQUEST_QUERY_PARAMS_WHITELIST = [
|
||||
|
||||
var lzmaWorker = new LZMA();
|
||||
|
||||
|
||||
var WELCOME_MSG = "This is the CartoDB Maps API, " +
|
||||
"see the documentation at http://docs.cartodb.com/cartodb-platform/maps-api.html";
|
||||
|
||||
|
||||
var timeoutErrorTilePath = __dirname + '/../../assets/render-timeout-fallback.png';
|
||||
var timeoutErrorTile = require('fs').readFileSync(timeoutErrorTilePath, {encoding: null});
|
||||
|
||||
|
||||
|
||||
module.exports = function(serverOptions) {
|
||||
// Make stats client globally accessible
|
||||
global.statsClient = windshaft.stats.Client.getInstance(serverOptions.statsd);
|
||||
@ -339,40 +331,15 @@ module.exports = function(serverOptions) {
|
||||
namedMapsAdminController = new NamedMapsAdminController(app, templateMaps, template_baseurl);
|
||||
namedMapsAdminController.register(app);
|
||||
|
||||
var healthCheck = new HealthCheck();
|
||||
app.get('/health', function(req, res) {
|
||||
var healthConfig = global.environment.health || {};
|
||||
|
||||
if (!!healthConfig.enabled) {
|
||||
var startTime = Date.now();
|
||||
healthCheck.check(healthConfig, function(err, result) {
|
||||
var ok = !err;
|
||||
var response = {
|
||||
enabled: true,
|
||||
ok: ok,
|
||||
elapsed: Date.now() - startTime,
|
||||
result: result
|
||||
};
|
||||
if (err) {
|
||||
response.err = err.message;
|
||||
}
|
||||
res.send(response, ok ? 200 : 503);
|
||||
|
||||
});
|
||||
} else {
|
||||
res.send({enabled: false, ok: true}, 200);
|
||||
}
|
||||
});
|
||||
|
||||
// simple testable route
|
||||
app.get('/', function(req, res) {
|
||||
app.sendResponse(res, [WELCOME_MSG]);
|
||||
});
|
||||
|
||||
// version
|
||||
app.get('/version', function(req, res) {
|
||||
app.sendResponse(res, [app.getVersion(), 200]);
|
||||
});
|
||||
var ServerInfoController = require('./controllers/server_info'),
|
||||
serverInfoController = new ServerInfoController({
|
||||
windshaft: windshaft.version,
|
||||
grainstore: grainstore.version(),
|
||||
node_mapnik: mapnik.version,
|
||||
mapnik: mapnik.versions.mapnik,
|
||||
windshaft_cartodb: require('../../package.json').version
|
||||
});
|
||||
serverInfoController.register(app);
|
||||
|
||||
/*******************************************************************************************************************
|
||||
* END Routing
|
||||
@ -391,17 +358,6 @@ module.exports = function(serverOptions) {
|
||||
}
|
||||
});
|
||||
|
||||
app.getVersion = function() {
|
||||
return {
|
||||
windshaft: windshaft.version,
|
||||
grainstore: grainstore.version(),
|
||||
node_mapnik: mapnik.version,
|
||||
mapnik: mapnik.versions.mapnik,
|
||||
windshaft_cartodb: require('../../package.json').version
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// GET routes for which we don't want to request any caching.
|
||||
// POST/PUT/DELETE requests are never cached anyway.
|
||||
var noCacheGETRoutes = [
|
||||
|
Loading…
Reference in New Issue
Block a user