-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (29 loc) · 803 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
30
31
32
33
34
35
36
37
38
const express = require("express");
const cors = require("cors");
const path = require("path");
const figuresRouter = require("./src/routes/figures");
const app = express();
const port = 3000;
require("dotenv").config();
const corsOptions = {
origin: "*",
};
app.use(cors(corsOptions));
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use("/", express.static(path.join(__dirname, "/src/docs")));
app.use("/figures", figuresRouter);
/* Error handler middleware */
app.use((err, req, res, next) => {
const statusCode = err.statusCode || 500;
console.error(err.message, err.stack);
res.status(statusCode).json({ message: err.message });
return;
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});