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')