Added api route to retrieve bot commands list.
This commit is contained in:
37
src/app/api/bot/route.ts
Normal file
37
src/app/api/bot/route.ts
Normal file
@@ -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
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@ const LineChartComponent = ({
|
|||||||
tickLine={false}
|
tickLine={false}
|
||||||
tickMargin={10}
|
tickMargin={10}
|
||||||
stroke={chart.color("border")}
|
stroke={chart.color("border")}
|
||||||
// label={{ value: label, position: "left", angle: -90 }}
|
// label={{ value: label, position: "left", angle: -90 }}
|
||||||
/>
|
/>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
animationDuration={100}
|
animationDuration={100}
|
||||||
|
|||||||
Reference in New Issue
Block a user