Skip to content

Commit

Permalink
feat: Add a health check endpoint. (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
cullylarson authored Apr 12, 2023
1 parent 5b21788 commit 862bb59
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/create-bison-app/template/pages/api/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { prisma } from '@/lib/prisma';

export default async function handler(_req: NextApiRequest, res: NextApiResponse) {
let databaseWorking = false;

try {
await prisma.user.findFirst();
databaseWorking = true;
} catch (err) {}

const data = {
env: {
NODE_ENV: process.env.NODE_ENV,
NEXT_PUBLIC_APP_ENV: process.env.NEXT_PUBLIC_APP_ENV,
SHOULD_MIGRATE: process.env.SHOULD_MIGRATE,
FC_GIT_COMMIT_SHA: process.env.FC_GIT_COMMIT_SHA,
},
status: {
database: databaseWorking,
},
};

const healthy = databaseWorking;

const statusCode = healthy ? 200 : 503;

res.status(statusCode).json(data);
}

0 comments on commit 862bb59

Please sign in to comment.