1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/lib/routes/health-check.js

32 lines
719 B
JavaScript

'use strict';
const { Router } = require('express');
const logger = require('../logger')('health-check.js');
class HealthCheckController {
constructor(config) {
const app = Router();
this.app = app;
this.db = config.stores.db;
app.get('/', (req, res) => this.index(req, res));
}
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' });
}
}
router() {
return this.app;
}
}
module.exports = HealthCheckController;