2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2018-11-24 12:43:46 +01:00
|
|
|
const logger = require('../logger')('health-check.js');
|
2018-12-03 08:59:13 +01:00
|
|
|
const Controller = require('./controller');
|
2018-11-24 12:43:46 +01:00
|
|
|
|
2018-12-03 08:59:13 +01:00
|
|
|
class HealthCheckController extends Controller {
|
2018-11-24 12:43:46 +01:00
|
|
|
constructor(config) {
|
2018-12-03 08:59:13 +01:00
|
|
|
super();
|
2018-11-24 12:43:46 +01:00
|
|
|
this.db = config.stores.db;
|
|
|
|
|
2018-12-03 08:59:13 +01:00
|
|
|
this.get('/', (req, res) => this.index(req, res));
|
2018-11-24 12:43:46 +01:00
|
|
|
}
|
2015-10-02 13:46:03 +02:00
|
|
|
|
2018-11-24 12:43:46 +01:00
|
|
|
async index(req, res) {
|
|
|
|
try {
|
|
|
|
await this.db.select(1).from('features');
|
|
|
|
res.json({ health: 'GOOD' });
|
|
|
|
} catch (e) {
|
|
|
|
logger.error('Could not select from features, error was: ', e);
|
|
|
|
res.status(500).json({ health: 'BAD' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2018-11-24 12:43:46 +01:00
|
|
|
module.exports = HealthCheckController;
|