-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (26 loc) · 867 Bytes
/
index.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
const express = require("express");
const app = express();
const dotenv = require("dotenv");
const mainHandler = require("./routes/main_handler");
const multipleMainHandler = require("./routes/multiple_main_handler");
const landingPageHandler = require("./routes/landing_page_handler");
const cors = require("cors");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
dotenv.config();
const port = process.env.PORT || 3002;
app.use("/", landingPageHandler);
app.use("/test", mainHandler);
app.use("/multi", multipleMainHandler);
app.use(errorHandler);
//default error handler
function errorHandler(err, req, res, next) {
if (res.headersSent) {
return next(err);
}
res.status(500).json({ error: err, message: err.message });
}
app.listen(port, () => {
console.log("App listening at port " + port);
});