-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (29 loc) · 833 Bytes
/
app.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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const user = require("./routes/user");
const moduleRoute = require("./routes/module");
const bodyParser = require("body-parser");
const sequelize = require("./util/database");
//NOTE: Run with cmd terminal to use nodemon
const app = express();
sequelize
.sync()
.then((result) => {
app.listen(parseInt(process.env.PORT));
})
.catch((e) => {
console.log("Failed to sync", e);
});
app.use(cors());
app.options('*', cors());
app.use(bodyParser.json());
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
next();
});
app.use("/user", user);
app.use("/module", moduleRoute);
app.get("*", (req, res) => {
res.status(404).send({ error: "Invalid path" });
});