Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions packages/auth/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,30 @@ export class App {

koa.use(bodyParser())

const redis = await this.container.use('redis')
koa.use(
async (
ctx: {
path: string
status: number
},
next: Koa.Next
): Promise<void> => {
if (ctx.path === '/healthz') {
const knex = await this.container.use('knex')
try {
await redis.ping()
await knex.raw('SELECT 1')
ctx.status = 200
} catch (err) {
ctx.status = 500
}
} else {
return next()
}
}
)

koa.use(
async (
ctx: {
Expand Down Expand Up @@ -268,8 +292,16 @@ export class App {

const router = new Router<DefaultState, AppContext>()
router.use(bodyParser())
router.get('/healthz', (ctx: AppContext): void => {
ctx.status = 200
router.get('/healthz', async (ctx: AppContext): Promise<void> => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add this route for the Admin API as well (like in backend)

const redis = await this.container.use('redis')
const knex = await this.container.use('knex')
try {
await redis.ping()
await knex.raw('SELECT 1')
ctx.status = 200
} catch (e) {
ctx.status = 500
}
})
router.use(gnapServerErrorMiddleware)

Expand Down Expand Up @@ -413,8 +445,16 @@ export class App {

const router = new Router<DefaultState, AppContext>()
router.use(bodyParser())
router.get('/healthz', (ctx: AppContext): void => {
ctx.status = 200
router.get('/healthz', async (ctx: AppContext): Promise<void> => {
const redis = await this.container.use('redis')
const knex = await this.container.use('knex')
try {
await redis.ping()
await knex.raw('SELECT 1')
ctx.status = 200
} catch (e) {
ctx.status = 500
}
})

const accessTokenRoutes = await this.container.use('accessTokenRoutes')
Expand Down Expand Up @@ -505,8 +545,16 @@ export class App {

koa.use(errorHandler)

router.get('/healthz', (ctx: AppContext): void => {
ctx.status = 200
router.get('/healthz', async (ctx: AppContext): Promise<void> => {
const redis = await this.container.use('redis')
const knex = await this.container.use('knex')
try {
await redis.ping()
await knex.raw('SELECT 1')
ctx.status = 200
} catch (e) {
ctx.status = 500
}
})

const tenantRoutes = await this.container.use('tenantRoutes')
Expand Down
21 changes: 18 additions & 3 deletions packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,14 @@ export class App {
next: Koa.Next
): Promise<void> => {
if (ctx.path === '/healthz') {
ctx.status = 200
const knex = await this.container.use('knex')
try {
await redis.ping()
await knex.raw('SELECT 1')
ctx.status = 200
} catch (err) {
ctx.status = 500
}
} else if (ctx.path !== '/graphql') {
ctx.status = 404
} else {
Expand Down Expand Up @@ -479,8 +486,16 @@ export class App {

const router = new Router<DefaultState, AppContext>()
router.use(bodyParser())
router.get('/healthz', (ctx: AppContext): void => {
ctx.status = 200
router.get('/healthz', async (ctx: AppContext): Promise<void> => {
const redis = await ctx.container.use('redis')
const knex = await ctx.container.use('knex')
try {
await redis.ping()
await knex.raw('SELECT 1')
ctx.status = 200
} catch (e) {
ctx.status = 500
}
})
router.use(openPaymentsServerErrorMiddleware)

Expand Down
Loading