webhook / server.ts
julien-c's picture
julien-c HF staff
Protect webhook with `X-Webhook-Secret`
b865405 verified
raw
history blame
525 Bytes
import * as express from "express";
const app = express();
// parse HTTP request bodies as json
app.use(express.json());
app.get("/", (req, res) => {
res.json({ hello: "world" });
});
app.post("/", (req, res) => {
if (req.header("X-Webhook-Secret") !== process.env.WEBHOOK_SECRET) {
return res.status(400).json({ error: "incorrect secret" });
}
console.log(req.body);
res.json({ success: true });
});
const PORT = 7860;
app.listen(PORT, () => {
console.debug(`server started at http://localhost:${PORT}`);
});