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.
This commit is contained in:
parent
48a50b5628
commit
e2e66f86bf
|
|
@ -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',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -99,3 +99,9 @@ router
|
||||||
router.post('delete', '#controllers/categories_controller.destroy')
|
router.post('delete', '#controllers/categories_controller.destroy')
|
||||||
})
|
})
|
||||||
.prefix('api/categories')
|
.prefix('api/categories')
|
||||||
|
|
||||||
|
router
|
||||||
|
.group(() => {
|
||||||
|
router.get('/', '#controllers/healcheck_controller.check')
|
||||||
|
})
|
||||||
|
.prefix('atc/health-check')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue