-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (27 loc) · 814 Bytes
/
index.js
File metadata and controls
35 lines (27 loc) · 814 Bytes
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
require("./config")();
const express = require("express");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const router = require("./routing");
const {getUser} = require("./middlewares/authentication");
require("./configDatabase")();
const app = express();
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}));
app.use(cookieParser());
app.use(express.json());
app.use(getUser);
app.use("/", router);
//If express.json body is invalid
app.use((err, req, res, next) => {
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
return res.status(400).send({ message: "Invalid body" });
}
next();
});
process.env;
app.listen(process.env.PORT, function () {
console.log(`Listening on port ${process.env.PORT}`);
});