Fix raw body capture middleware
cgen-2d2ac1f9fd1540f984ef7323bca961f0
This commit is contained in:
parent
652cde8a81
commit
6dc998da3a
1 changed files with 13 additions and 7 deletions
|
|
@ -8,15 +8,21 @@ import { randomUUID, createHash, createVerify } from "crypto";
|
||||||
export function createServer() {
|
export function createServer() {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// Middleware - capture raw body for Discord signature verification
|
|
||||||
app.use((req, res, buf, encoding) => {
|
|
||||||
if (buf && buf.length) {
|
|
||||||
req.rawBody = buf.toString(encoding || 'utf8');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
app.use(cors());
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue