From e2e66f86bf6e7b1795e62545373055535818737e Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:19:16 +0700 Subject: [PATCH] Add health check endpoint and controller Introduces HealCheckController to perform a health check by posting to a wiki API. Adds a new route at /atc/health-check for accessing the health check functionality. --- .../app/controllers/healcheck_controller.ts | 38 +++++++++++++++++++ BACKEND/start/routes.ts | 6 +++ 2 files changed, 44 insertions(+) create mode 100644 BACKEND/app/controllers/healcheck_controller.ts diff --git a/BACKEND/app/controllers/healcheck_controller.ts b/BACKEND/app/controllers/healcheck_controller.ts new file mode 100644 index 0000000..34ac4da --- /dev/null +++ b/BACKEND/app/controllers/healcheck_controller.ts @@ -0,0 +1,38 @@ +import type { HttpContext } from '@adonisjs/core/http' +import axios from 'axios' + +export default class HealCheckController { + // GET /health-check + async check({}: HttpContext) { + try { + const linkWiki = + process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test' + const resWiki = await axios.post(linkWiki, { + data: 'Health checking', + healthChecking: true, + }) + return { + code: resWiki.status, + data: [ + { + name: 'wiki', + status: resWiki.status < 400 ? true : false, + message: resWiki.data?.message || 'Checking api wiki success', + }, + ], + } + } catch (error) { + console.log(error) + return { + code: 200, + data: [ + { + name: 'wiki', + status: false, + message: error?.message || 'Checking api wiki fail', + }, + ], + } + } + } +} diff --git a/BACKEND/start/routes.ts b/BACKEND/start/routes.ts index 123a8e0..5442557 100644 --- a/BACKEND/start/routes.ts +++ b/BACKEND/start/routes.ts @@ -99,3 +99,9 @@ router router.post('delete', '#controllers/categories_controller.destroy') }) .prefix('api/categories') + +router + .group(() => { + router.get('/', '#controllers/healcheck_controller.check') + }) + .prefix('atc/health-check')