From ec7187ecc4401b1706de05d47357b6b284cfec28 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Thu, 6 Nov 2025 07:30:31 +0000 Subject: [PATCH] completionId: cgen-94b0611ce8b4483ab9317301fa181f28 cgen-94b0611ce8b4483ab9317301fa181f28 --- server/index.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/index.ts b/server/index.ts index 4698d6d4..fc004c09 100644 --- a/server/index.ts +++ b/server/index.ts @@ -73,8 +73,18 @@ const handleDiscordInteractions = ( export function createServer() { const app = express(); + // Discord endpoint MUST be defined BEFORE any body parsing middleware + // and needs raw body for signature verification + app.post( + "/api/discord/interactions", + express.raw({ type: "application/json" }), + handleDiscordInteractions, + ); + // Middleware app.use(cors()); + app.use(express.json()); + app.use(express.urlencoded({ extended: true })); // Allow Discord to embed the activity in iframes app.use((req, res, next) => { @@ -93,16 +103,6 @@ export function createServer() { next(); }); - // Discord endpoint needs raw body for signature verification - app.post( - "/api/discord/interactions", - express.raw({ type: "application/json" }), - handleDiscordInteractions, - ); - - app.use(express.json()); - app.use(express.urlencoded({ extended: true })); - // Example API routes app.get("/api/ping", (_req, res) => { const ping = process.env.PING_MESSAGE ?? "ping";