- Add @ketopath/db and fastify-plugin to apps/api - prismaPlugin decorates the Fastify instance with prisma and disconnects on app close, with FastifyInstance type augmented in src/types/fastify.d.ts - DATABASE_URL is now required by env validation - New module modules/db with GET /db/health running SELECT 1 via Prisma - dev script switched to tsx --env-file=.env for env loading Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
14 lines
468 B
TypeScript
14 lines
468 B
TypeScript
import type { FastifyPluginAsync } from 'fastify';
|
|
|
|
export const dbRoutes: FastifyPluginAsync = async (fastify) => {
|
|
fastify.get('/db/health', async (_request, reply) => {
|
|
try {
|
|
await fastify.prisma.$queryRaw`SELECT 1`;
|
|
return { status: 'ok', database: 'reachable' };
|
|
} catch (err) {
|
|
fastify.log.error({ err }, 'database health check failed');
|
|
return reply.code(503).send({ status: 'error', database: 'unreachable' });
|
|
}
|
|
});
|
|
};
|