Skip to content

Commit

Permalink
feat(health): couple the health check with a operation that depends o…
Browse files Browse the repository at this point in the history
…n redis
  • Loading branch information
hugotiburtino committed Jul 22, 2024
1 parent c4992ad commit 4e99b8b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions packages/server/src/internals/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createCache, createEmptyCache } from '~/cache'
import { createAuthServices, AuthServices } from '~/context/auth-services'
import { Cache } from '~/context/cache'
import { SwrQueue } from '~/context/swr-queue'
import { captureErrorEvent } from '~/error-event'
import { applyEnmeshedMiddleware } from '~/internals/server/enmeshed-middleware'
import { applyKratosMiddleware } from '~/internals/server/kratos-middleware'
import { Timer, createTimer } from '~/timer'
Expand Down Expand Up @@ -70,8 +71,30 @@ async function initializeServer({
})
const enmeshedPath = applyEnmeshedMiddleware({ app, cache })

app.get(healthPath, (_req, res) => {
res.status(200).send('Okay!')
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.get(healthPath, async (_req, res) => {
try {
const response = await fetch('http://localhost:3001/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: '{ uuid(id: 1) { id } }' }),
})
const data: unknown = await response.json()
if (typeof data !== 'object' || !data || 'errors' in data) {
return res
.status(500)
.send('Graphql operations dependent on Redis are broken')
}
res.status(200).send('Okay!')
} catch (error) {
res.status(500).send(`Unexpected error occurred`)
captureErrorEvent({
error: error as Error,
location: '/health',
})
}
})

const port = 3001
Expand Down

0 comments on commit 4e99b8b

Please sign in to comment.