Use proper raw body middleware for Discord endpoint

cgen-90c43c93d3c04e718da25f8e3141c230
This commit is contained in:
Builder.io 2025-11-05 17:17:58 +00:00
parent 6dc998da3a
commit 9bb59d497e

View file

@ -11,17 +11,12 @@ export function createServer() {
// Middleware
app.use(cors());
// Capture raw body for Discord signature verification
app.use((req, res, next) => {
let rawBody = '';
req.on('data', (chunk) => {
rawBody += chunk.toString('utf8');
});
req.on('end', () => {
(req as any).rawBody = rawBody;
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 }));