services-api-handler.class.ts 888 B

123456789101112131415161718192021222324252627282930
  1. import { RouterOptions } from 'express';
  2. import { HttpStatusException } from '../../../common/lib/http-status.exception';
  3. import { ControllerPool } from '../ctrl/controller-pool.interface';
  4. import { WebHandler } from './web-handler.base';
  5. export class ServicesAPIHandler extends WebHandler {
  6. constructor(protected ctrlPool: ControllerPool, options?: RouterOptions) {
  7. super(ctrlPool, options);
  8. this.router.use(this.avoidCache);
  9. this.router.get('/:serverID', async (req, res, next) => {
  10. try {
  11. const serverID = Number(req.params.serverID);
  12. if (Number.isNaN(serverID)) {
  13. throw new HttpStatusException(`Not a valid server id: ${req.params.serverID}`, 400);
  14. }
  15. const services = await this.ctrlPool.db.getHealthCheckConfigs(serverID);
  16. res.send(services);
  17. } catch (err) {
  18. next(err);
  19. }
  20. });
  21. }
  22. }