Create server.js
Browse files
server.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require("express");
|
| 2 |
+
const bodyParser = require("body-parser");
|
| 3 |
+
const webhookRoutes = require("./api/webhook");
|
| 4 |
+
|
| 5 |
+
require("dotenv").config();
|
| 6 |
+
|
| 7 |
+
const app = express();
|
| 8 |
+
app.use(bodyParser.json());
|
| 9 |
+
|
| 10 |
+
// Webhook GET route
|
| 11 |
+
|
| 12 |
+
app.use((req, res, next) => {
|
| 13 |
+
if (req.path.substr(-1) === "/" && req.path.length > 1) {
|
| 14 |
+
res.redirect(301, req.path.slice(0, -1));
|
| 15 |
+
} else {
|
| 16 |
+
next();
|
| 17 |
+
}
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
// Use the webhook routes
|
| 22 |
+
app.use("/webhook", webhookRoutes);
|
| 23 |
+
app.get("/test", (req, res) => {
|
| 24 |
+
res.send("Test route works!");
|
| 25 |
+
});
|
| 26 |
+
|
| 27 |
+
app.get("/", (req, res) => {
|
| 28 |
+
res.status(200).send("Home route works!");
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
// Start the server
|
| 32 |
+
const PORT = process.env.PORT || 3000;
|
| 33 |
+
app.listen(PORT, () => {
|
| 34 |
+
console.log(`Server running on port ${PORT}`);
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|