From 9aea53aef71b8f633faee2c11c5f32336a198010 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 24 Feb 2023 19:40:38 -0600 Subject: [PATCH] Add atomic health check API route --- src/pages/api/health.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/pages/api/health.ts diff --git a/src/pages/api/health.ts b/src/pages/api/health.ts new file mode 100644 index 0000000..c66d1de --- /dev/null +++ b/src/pages/api/health.ts @@ -0,0 +1,18 @@ +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import type { NextApiRequest, NextApiResponse } from "next"; +import { env } from "@/env/server.mjs"; + +type ResponseData = { + now: number; + status: string; +}; + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse +) { + res.status(200).json({ + now: new Date().getTime(), + status: req.query.key == env.API_KEY ? "Authorized" : "Unauthorized", + }); +}