diff --git a/utils/monitorServer.js b/utils/monitorServer.js index 0d4a67a..e567083 100644 --- a/utils/monitorServer.js +++ b/utils/monitorServer.js @@ -1,17 +1,28 @@ const logger = require('./logger'); const axios = require('axios'); -const HEALTH_CHECK_URL = process.env.HEALTH_CHECK_URL +const HEALTH_CHECK_URL = process.env.HEALTH_CHECK_URL; + +if (!HEALTH_CHECK_URL) { + throw new Error('HEALTH_CHECK_URL is not configured'); +} const monitorServer = async () => { try { - const health = await axios.get(`${HEALTH_CHECK_URL}`) - logger.info(health.data) + const response = await axios.get(HEALTH_CHECK_URL, { + timeout: 5000 + }); + + logger.info( + `Health check passed - Status: ${response.status}` + ); } catch (error) { - logger.error('Server is down: ', error.message) + logger.error( + `Health check failed - ${error.message}` + ); } -} +}; + +monitorServer(); -setInterval(() =>{ - monitorServer() -}, 1000 * 60 * 14) \ No newline at end of file +setInterval(monitorServer, 1000 * 60 * 14); \ No newline at end of file