diff --git a/src/app/api/bot/route.ts b/src/app/api/bot/route.ts new file mode 100644 index 0000000..f91c8b0 --- /dev/null +++ b/src/app/api/bot/route.ts @@ -0,0 +1,37 @@ +import { headers } from "next/headers"; +import botCommands from "@/data/botCommands"; + +const environment = process.env.NODE_ENV || "development"; + +const isValidApiKey = (apiKey: string): boolean => { + const envApiKey = + process.env.API_TOKEN || process.env.NEXT_PUBLIC_API_TOKEN || ""; + + return apiKey === envApiKey; +}; + +export async function GET(/*request: Request*/) { + const headersList = await headers(); + const apiKey = headersList.get("x-api-key"); + + if (environment === "production") { + if (!apiKey || apiKey == null) { + return new Response("No API Key provided", { + status: 401, + headers: headersList + }); + } + + if (apiKey !== null && !(await isValidApiKey(apiKey))) { + return new Response("Invalid API Key", { + status: 403, + headers: headersList + }); + } + } + + return Response.json(botCommands, { + status: 200, + headers: headersList + }); +} diff --git a/src/components/charts/LineChart.tsx b/src/components/charts/LineChart.tsx index 7c9833e..467a918 100644 --- a/src/components/charts/LineChart.tsx +++ b/src/components/charts/LineChart.tsx @@ -40,7 +40,7 @@ const LineChartComponent = ({ tickLine={false} tickMargin={10} stroke={chart.color("border")} - // label={{ value: label, position: "left", angle: -90 }} + // label={{ value: label, position: "left", angle: -90 }} />