Use proper raw body middleware for Discord endpoint
cgen-90c43c93d3c04e718da25f8e3141c230
This commit is contained in:
parent
6dc998da3a
commit
9bb59d497e
1 changed files with 6 additions and 11 deletions
|
|
@ -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 }));
|
||||
|
|
|
|||
Loading…
Reference in a new issue