import express from "express";
import { Webhook } from "svix";
const app = express();
app.use(express.raw({ type: "application/json" }));
app.post("/webhooks", (req, res) => {
const wh = new Webhook(process.env.WEBHOOK_SECRET!);
let event;
try {
event = wh.verify(req.body, req.headers as any);
} catch (err) {
return res.status(400).send("Invalid signature");
}
// Deduplicate using webhook-id
const webhookId = req.headers["webhook-id"] as string;
if (alreadyProcessed(webhookId)) {
return res.status(200).send("Duplicate, skipping");
}
console.log("Received event:", event);
res.status(200).send("OK");
});