radio-station/app/routes/healthcheck.tsx
Luke Bunselmeyer 78c07c40cc - Fixed E2E smoke tests
- Added unit test for `slugify`
- Updated readme
2023-05-08 00:55:06 -04:00

26 lines
916 B
TypeScript

// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
import type { LoaderArgs } from "@remix-run/node";
import { prisma } from "~/db.server";
export const loader = async ({ request }: LoaderArgs) => {
const host =
request.headers.get("X-Forwarded-Host") ?? request.headers.get("host");
try {
const url = new URL("/", `http://${host}`);
// 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(url.toString(), { method: "HEAD" }).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 });
}
};