Add healthcheck endpoint (close #140)
This commit is contained in:
parent
d30027e992
commit
5d93b1d4f9
3 changed files with 24 additions and 0 deletions
|
@ -64,3 +64,10 @@ Array of all TileJSONs is at ``/index.json`` (``/rendered.json``; ``/data.json``
|
|||
List of available fonts
|
||||
=======================
|
||||
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
|
||||
|
|
|
@ -375,8 +375,17 @@ function start(opts) {
|
|||
return data;
|
||||
});
|
||||
|
||||
var startupComplete = false;
|
||||
var startupPromise = Promise.all(startupPromises).then(function() {
|
||||
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() {
|
||||
|
|
|
@ -38,6 +38,14 @@ var testTileJSON = function(url) {
|
|||
};
|
||||
|
||||
describe('Metadata', function() {
|
||||
describe('/health', function() {
|
||||
it('returns 200', function(done) {
|
||||
supertest(app)
|
||||
.get('/health')
|
||||
.expect(200, done);
|
||||
});
|
||||
});
|
||||
|
||||
testTileJSONArray('/index.json');
|
||||
testTileJSONArray('/rendered.json');
|
||||
testTileJSONArray('/data.json');
|
||||
|
|
Loading…
Reference in a new issue