export const POST = async (req: Request,res: Response) => {
const webhookSignature = req.headers.get("X-Dock-Signature");
if (!webhookSignature) {
return res.status(401).send("No signature provided.");
}
// Copy this from the webhook details page
const secret = process.env.DOCK_WEBHOOK_SECRET;
if (!secret) {
return res.status(401).send("No secret provided.");
}
// Make sure to get the body from the request
const url = `https://${req.header('host')}${req.path}`;
const body = JSON.stringify(req.body);
const payload = `${req.method}\n${url}\n${body}`;
const computedSignature = crypto
.createHmac("sha256", secret)
.update(payload)
.digest("hex");
if (crypto.timingSafeEqual(
Buffer.from(webhookSignature, 'hex'),
Buffer.from(computedSignature, 'hex'),
)) {
return res.status(400).send("Invalid signature");
}
// Handle the webhook event
// ...
};