Parcourir la source

Merge pull request #2633 from overleaf/bg-fix-health-check-for-web-api

fix the health check on the api router

GitOrigin-RevId: 985322f8e4ff0b5dddbe7cf68c41414af6fd502d
Brian Gough il y a 6 ans
Parent
commit
fc028c7544

+ 20 - 0
services/web/app/src/Features/HealthCheck/HealthCheckController.js

@@ -57,6 +57,26 @@ module.exports = HealthCheckController = {
     })
     })
   },
   },
 
 
+  checkApi(req, res, next) {
+    rclient.healthCheck(err => {
+      if (err) {
+        logger.err({ err }, 'failed api redis health check')
+        return res.sendStatus(500)
+      }
+      UserGetter.getUserEmail(settings.smokeTest.userId, (err, email) => {
+        if (err) {
+          logger.err({ err }, 'failed api mongo health check')
+          return res.sendStatus(500)
+        }
+        if (email == null) {
+          logger.err({ err }, 'failed api mongo health check (no email)')
+          return res.sendStatus(500)
+        }
+        res.sendStatus(200)
+      })
+    })
+  },
+
   checkRedis(req, res, next) {
   checkRedis(req, res, next) {
     return rclient.healthCheck(function(error) {
     return rclient.healthCheck(function(error) {
       if (error != null) {
       if (error != null) {

+ 1 - 1
services/web/app/src/router.js

@@ -969,7 +969,7 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
   webRouter.get('/dev/csrf', (req, res) => res.send(res.locals.csrfToken))
   webRouter.get('/dev/csrf', (req, res) => res.send(res.locals.csrfToken))
 
 
   publicApiRouter.get('/health_check', HealthCheckController.check)
   publicApiRouter.get('/health_check', HealthCheckController.check)
-  privateApiRouter.get('/health_check', HealthCheckController.check)
+  privateApiRouter.get('/health_check', HealthCheckController.checkApi)
 
 
   publicApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)
   publicApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)
   privateApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)
   privateApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)