mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
webhook calls moved server-side
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user