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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,8 +29,8 @@ export const handleTournamentSubmit = async (
|
|||||||
setIsSending(true);
|
setIsSending(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await tournamentFormToDB(formRefs); // write to DB
|
|
||||||
await discordWebhook(formRefs); // send Discord notification
|
await discordWebhook(formRefs); // send Discord notification
|
||||||
|
await tournamentFormToDB(formRefs); // write to DB
|
||||||
setIsSending(false);
|
setIsSending(false);
|
||||||
setResponseMessage({
|
setResponseMessage({
|
||||||
isSuccessful: true,
|
isSuccessful: true,
|
||||||
|
|||||||
@@ -10,12 +10,6 @@ const discordWebhook = async ({
|
|||||||
yourEmailRef,
|
yourEmailRef,
|
||||||
messageRef,
|
messageRef,
|
||||||
}: TournamentFormProps) => {
|
}: TournamentFormProps) => {
|
||||||
const webhookURL = process.env.NEXT_PUBLIC_DISCORD_WEBHOOK;
|
|
||||||
|
|
||||||
if (!webhookURL) {
|
|
||||||
throw new Error("Discord webhook URL is not defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
const webhookBody = {
|
const webhookBody = {
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
@@ -36,7 +30,7 @@ const discordWebhook = async ({
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
return await fetch(webhookURL, {
|
return await fetch("/api/send-discord-notification", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
Reference in New Issue
Block a user