-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (32 loc) · 1.09 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import express from "express";
import path from "path";
import { fileURLToPath } from "url";
const app = express();
const PORT = 3000;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(express.json());
app.use(express.static(path.join(__dirname, "public")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
});
app.post("/webhook", (req, res) => {
const { challenge, type } = req.body;
if (type === "URL_VERIFICATION" && challenge) {
console.log("Webhook verification handshake received");
res.status(200).json({ challenge });
} else {
res.status(400).json({ error: "Bad Request: Invalid payload" });
}
});
app.use((req, res) => {
console.error(`Route not found: ${req.method} ${req.url}`);
res.status(404).json({ error: "Not Found" });
});
app.use((err, req, res, next) => {
console.error("Internal Server Error:", err.stack);
res.status(500).json({ error: "Internal Server Error" });
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});