import Router from '@koa/router';
import Koa from 'koa';
import { inject } from '@cardstack/di';
import DatabaseManager from '@cardstack/db';

export default class HealthCheck {
  databaseManager: DatabaseManager = inject('database-manager', { as: 'databaseManager' });
  routes() {
    let healthCheckRouter = new Router();
    healthCheckRouter.all('/', async (ctx: Koa.Context) => {
      let db = await this.databaseManager.getClient();
      await db.query('SELECT 1');
      ctx.status = 200;
      let body = `
Cardstack Hub
-------------
Up and running at ${new Date().toISOString()}
${
  process.env.WAYPOINT_DEPLOYMENT_ID
    ? `Deployment ID: ${process.env.WAYPOINT_DEPLOYMENT_ID}`
    : 'Running outside of Waypoint'
}
`;
      ctx.body = body;
    });

    return healthCheckRouter.routes();
  }
}

declare module '@cardstack/hub/services' {
  interface HubServices {
    'health-check': HealthCheck;
  }
}

import Router from '@koa/router';
import Koa from 'koa';
import { inject } from '@cardstack/di';
import DatabaseManager from '@cardstack/db';

export default class HealthCheck {
  databaseManager: DatabaseManager = inject('database-manager', { as: 'databaseManager' });
  routes() {
    let healthCheckRouter = new Router();
    healthCheckRouter.all('/', async (ctx: Koa.Context) => {
      let db = await this.databaseManager.getClient();
      await db.query('SELECT 1');
      ctx.status = 200;
      ctx.body = `Cardstack Hub is up and running at ${new Date().toISOString()}`;
    });

    return healthCheckRouter.routes();
  }
}

declare module '@cardstack/hub/services' {
  interface HubServices {
    'health-check': HealthCheck;
  }
}

--- 
+++ 
@@ -11,7 +11,17 @@
       let db = await this.databaseManager.getClient();
       await db.query('SELECT 1');
       ctx.status = 200;
-      ctx.body = `Cardstack Hub is up and running at ${new Date().toISOString()}`;
+      let body = `
+Cardstack Hub
+-------------
+Up and running at ${new Date().toISOString()}
+${
+  process.env.WAYPOINT_DEPLOYMENT_ID
+    ? `Deployment ID: ${process.env.WAYPOINT_DEPLOYMENT_ID}`
+    : 'Running outside of Waypoint'
+}
+`;
+      ctx.body = body;
     });
 
     return healthCheckRouter.routes();
Improve health check response to include WAYPOINT_DEPLOYMENT_ID

- so that it is easier to see when deployments are live
