mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-22 20:16:57 +00:00
35 lines
815 B
TypeScript
35 lines
815 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const webhookURL = process.env.DISCORD_WEBHOOK_URL;
|
|
const { embeds } = await req.json();
|
|
|
|
if (!webhookURL) {
|
|
return NextResponse.json(
|
|
{ error: `Discord webhook URL not found` },
|
|
{ status: 404 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
const webhookBody = {
|
|
embeds: embeds,
|
|
};
|
|
|
|
const webhookInfo = await fetch(webhookURL, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(webhookBody),
|
|
});
|
|
|
|
return NextResponse.json(
|
|
{ success: `Message delivered to ${webhookInfo}` },
|
|
{ status: 200 },
|
|
);
|
|
} catch (error) {
|
|
return NextResponse.json({ error: `Connection refused` }, { status: 404 });
|
|
}
|
|
}
|