Spaces:
Build error
Build error
Protect webhook with `X-Webhook-Secret`
Browse files
server.ts
CHANGED
@@ -1,12 +1,18 @@
|
|
1 |
import * as express from "express";
|
2 |
|
3 |
-
const
|
|
|
|
|
4 |
|
5 |
-
|
6 |
res.json({ hello: "world" });
|
7 |
});
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
console.log(req.body);
|
11 |
|
12 |
res.json({ success: true });
|
@@ -14,6 +20,6 @@ expressApp.post("/", (req, res) => {
|
|
14 |
|
15 |
|
16 |
const PORT = 7860;
|
17 |
-
|
18 |
console.debug(`server started at http://localhost:${PORT}`);
|
19 |
});
|
|
|
1 |
import * as express from "express";
|
2 |
|
3 |
+
const app = express();
|
4 |
+
// parse HTTP request bodies as json
|
5 |
+
app.use(express.json());
|
6 |
|
7 |
+
app.get("/", (req, res) => {
|
8 |
res.json({ hello: "world" });
|
9 |
});
|
10 |
|
11 |
+
app.post("/", (req, res) => {
|
12 |
+
|
13 |
+
if (req.header("X-Webhook-Secret") !== process.env.WEBHOOK_SECRET) {
|
14 |
+
return res.status(400).json({ error: "incorrect secret" });
|
15 |
+
}
|
16 |
console.log(req.body);
|
17 |
|
18 |
res.json({ success: true });
|
|
|
20 |
|
21 |
|
22 |
const PORT = 7860;
|
23 |
+
app.listen(PORT, () => {
|
24 |
console.debug(`server started at http://localhost:${PORT}`);
|
25 |
});
|