-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (43 loc) · 1.35 KB
/
server.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const express = require("express");
const path = require("path");
const cors = require("cors");
const sequelize = require("./backend/DB/DBConnection");
const morgan = require("morgan");
const User = require("./backend/models/user");
const Movie = require("./backend/models/movie");
const app = express();
/* using Middlewares */
app.use("/static", express.static("public/static"));
app.use(express.static("frontend/build"));
app.use(cors());
app.use(morgan("dev"));
app.use(express.json({ limit: "500MB", extended: false }));
app.use(express.urlencoded({ extended: false }));
var session = require("express-session");
const { throws } = require("assert");
app.use(
session({
secret: "SECRET",
resave: false,
saveUninitialized: false,
})
);
app.disable("etag");
app.use("/api/auth", require("./backend/routes/auth"));
app.use("/api/movies", require("./backend/routes/movies"));
app.use((err, req, res, next) => {
res.status(500).json({ message: err.message });
});
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "frontend", "build", "index.html"));
});
User.hasMany(Movie);
const PORT = process.env.PORT || 5000;
sequelize
.sync()
.then(() => {
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
})
.catch((err) => {
console.log(err);
});