-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e82e12e
commit 6486491
Showing
2 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters