Skip to content

Commit

Permalink
update health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnmclean committed Jun 2, 2024
1 parent e82e12e commit 6486491
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions app/routes/_status+/health.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
import { type LoaderFunctionArgs } from '@remix-run/node'
import { prisma } from '#app/utils/db.server.ts'

export async function loader({ request }: LoaderFunctionArgs) {
const host =
request.headers.get('X-Forwarded-Host') ?? request.headers.get('host')

try {
// if we can connect to the database and make a simple query
// and make a HEAD request to ourselves, then we're good.
await Promise.all([
prisma.user.count(),
fetch(`${new URL(request.url).protocol}${host}`, {
method: 'HEAD',
headers: { 'X-Healthcheck': 'true' },
}).then(r => {
if (!r.ok) return Promise.reject(r)
}),
])
return new Response('OK')
} catch (error: unknown) {
console.log('healthcheck ❌', { error })
return new Response('ERROR', { status: 500 })
}
}
4 changes: 2 additions & 2 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ script_checks = [ ]
[[services.http_checks]]
interval = "10s"
grace_period = "5s"
method = "get"
path = "/resources/healthcheck"
method = "GET"
path = "/health"
protocol = "http"
timeout = "2s"
tls_skip_verify = false
Expand Down

0 comments on commit 6486491

Please sign in to comment.