Add healthcheck endpoint (close #140)

This commit is contained in:
Petr Sloup 2017-05-10 08:57:51 +02:00
parent d30027e992
commit 5d93b1d4f9
3 changed files with 24 additions and 0 deletions

View file

@ -64,3 +64,10 @@ Array of all TileJSONs is at ``/index.json`` (``/rendered.json``; ``/data.json``
List of available fonts List of available fonts
======================= =======================
Array of names of the available fonts is at ``/fonts.json`` Array of names of the available fonts is at ``/fonts.json``
Health check
============
Endpoint reporting health status is at ``/health`` and currently returns:
* ``503`` Starting - for a short period before everything is initialized
* ``200`` OK - when the server is running

View file

@ -375,8 +375,17 @@ function start(opts) {
return data; return data;
}); });
var startupComplete = false;
var startupPromise = Promise.all(startupPromises).then(function() { var startupPromise = Promise.all(startupPromises).then(function() {
console.log('Startup complete'); console.log('Startup complete');
startupComplete = true;
});
app.get('/health', function(req, res, next) {
if (startupComplete) {
return res.status(200).send('OK');
} else {
return res.status(503).send('Starting');
}
}); });
var server = app.listen(process.env.PORT || opts.port, process.env.BIND || opts.bind, function() { var server = app.listen(process.env.PORT || opts.port, process.env.BIND || opts.bind, function() {

View file

@ -38,6 +38,14 @@ var testTileJSON = function(url) {
}; };
describe('Metadata', function() { describe('Metadata', function() {
describe('/health', function() {
it('returns 200', function(done) {
supertest(app)
.get('/health')
.expect(200, done);
});
});
testTileJSONArray('/index.json'); testTileJSONArray('/index.json');
testTileJSONArray('/rendered.json'); testTileJSONArray('/rendered.json');
testTileJSONArray('/data.json'); testTileJSONArray('/data.json');