Add '/version' endpoint

Closes #138
Includes testcase
This commit is contained in:
Sandro Santilli 2014-03-13 13:40:56 +01:00
parent e8c315fe98
commit 622846b453
3 changed files with 25 additions and 0 deletions

View File

@ -4,6 +4,7 @@
New features:
* Add optional support for rollbar (#137)
* Add '/version' endpoint (#138)
Enhancements:

View File

@ -94,6 +94,13 @@ if ( global.settings.hasOwnProperty('node_socket_timeout') ) {
});
}
// Version extracting function
function getVersion() {
var version = {};
version.cartodb_sql_api = require(__dirname + '/../../package.json').version;
return version;
}
app.use(express.bodyParser());
app.enable('jsonp callback');
app.set("trust proxy", true);
@ -103,6 +110,9 @@ app.options('*', function(req,res) { setCrossDomain(res); res.end(); });
app.all(global.settings.base_url+'/sql', function(req, res) { handleQuery(req, res) } );
app.all(global.settings.base_url+'/sql.:f', function(req, res) { handleQuery(req, res) } );
app.get(global.settings.base_url+'/cachestatus', function(req, res) { handleCacheStatus(req, res) } );
app.get(global.settings.base_url+'/version', function(req, res) {
res.send(getVersion());
});
// Return true of the given query may write to the database
//

View File

@ -33,6 +33,20 @@ var expected_cache_control = 'no-cache,max-age=31536000,must-revalidate,public';
var expected_rw_cache_control = 'no-cache,max-age=0,must-revalidate,public';
var expected_cache_control_persist = 'public,max-age=31536000';
test('GET /api/v1/version', function(done){
assert.response(app, {
url: '/api/v1/version',
method: 'GET'
},{}, function(res) {
assert.equal(res.statusCode, 200);
var parsed = JSON.parse(res.body);
var sqlapi_version = require(__dirname + '/../../package.json').version;
assert.ok(parsed.hasOwnProperty('cartodb_sql_api'), "No 'cartodb_sql_api' version in " + parsed);
assert.equal(parsed.cartodb_sql_api, sqlapi_version);
done();
});
});
test('GET /api/v1/sql', function(done){
assert.response(app, {
url: '/api/v1/sql',