From 2514acdd3120382bd4009b4768d198be105bbeea Mon Sep 17 00:00:00 2001 From: "Dr. Alwin Simon" <003alwin@gmail.com> Date: Tue, 23 Jul 2024 20:11:07 +0530 Subject: [PATCH] Added a new route for server health check --- app/controllers/adminController.js | 25 ++++++++++++++++++++++++- routes/admin.js | 4 ++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/controllers/adminController.js b/app/controllers/adminController.js index efda51a..0f7e7dd 100644 --- a/app/controllers/adminController.js +++ b/app/controllers/adminController.js @@ -7,8 +7,30 @@ const userHelpers = require('../../helpers/user-helpers'); require('dotenv').config(); // Module to Load environment variables from .env file -const PLATFORM_NAME = process.env.PLATFORM_NAME || "GetMyDeal" +const PLATFORM_NAME = process.env.PLATFORM_NAME || "GetMyDeal"; + +/* ============================================= HEALTH STATUS CONTROLLER ============================================= */ + +const healthStatusGET = (req, res) => { + const currentDate = new Date(); + const options = { + weekday: "long", + year: "numeric", + month: "long", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + timeZone: "UTC", + }; + const formattedDate = currentDate.toLocaleString("en-US", options); + + res.status(200).json({ + status: `${process.env.APPLICATION_NAME} and Systems are Up & Running.`, + dateTime: formattedDate, + }); +}; /* ============================================= LOGIN & LOGOUT CONTROLLERS ============================================= */ @@ -576,6 +598,7 @@ const adminErrorHandlerPageGET = (req,res)=>{ module.exports = { + healthStatusGET, logInGET, logInPOST, logOutPOST, diff --git a/routes/admin.js b/routes/admin.js index 044c453..a500f5c 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -25,6 +25,10 @@ const multerUploadBannerImage = multer.uploadBannerImage.single('banner-image'); /*=================================================ADMIN ROUTES=================================================*/ +/* ========================HEALTH CHECK ROUTE======================== */ + +router.get('/health', adminController.healthStatusGET); + /* ========================LOGIN & LOGOUT ROUTES======================== */ router.get('/login', adminController.logInGET);