-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (48 loc) · 1.72 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require("dotenv-flow").config({
path: "./config",
});
console.log("MONGO_URI:", process.env.MONGO_URI);
console.log("NODE ENV:", process.env.NODE_ENV);
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const cors = require("cors");
app.use(bodyParser.json());
require("./models/User");
require("./models/SavedMovies");
mongoose.connect(process.env.MONGO_URI);
console.log("test");
app.use(express.static(__dirname, { dotfiles: "allow" }));
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", req.get("Origin") || "*");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE");
res.header("Access-Control-Expose-Headers", "Content-Length");
res.header(
"Access-Control-Allow-Headers",
"Accept, Authorization, Content-Type, X-Requested-With, Range"
);
if (req.method === "OPTIONS") {
return res.sendStatus(200);
}
return next();
});
app.options("*", cors());
app.use(cors());
app.get("/", (req, res) => {
res.send("hello world");
});
require("./routes/authRoutes")(app);
require("./routes/savedMovieRoutes")(app);
require("./routes/savedQueriesRoutes")(app);
require("./routes/watchMovieRoutes")(app);
require("./routes/aiMovieGeneratorRoutes")(app);
if (process.env.NODE_ENV === "production") {
//if the handlers above won't resolve the request it will go to the next route handler below
//Express will serve up production assests. Like our main.js or main.css
app.use(express.static("client/build"));
//if this handler cannot resolve it then go to the next one.
}
const PORT = process.env.PORT || 5000;
app.listen(PORT);