-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (43 loc) · 1.25 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
const express = require("express");
const app = express();
const cors = require("cors");
/*const corsOptions = {
origin: "*",
credentials: true, //access-control-allow-credentials:true
optionSuccessStatus: 200,
};*/
app.use(
cors({
origin:
"http://localhost:3000" || "https://enchanting-tuna-costume.cyclic.app",
})
);
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const path = require("path");
const authRoute = require("./routes/auth");
const userRoute = require("./routes/users");
const listRoute = require("./routes/lists");
const movieRoute = require("./routes/movies");
dotenv.config();
mongoose
.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("DB Connection Successfull"))
.catch((err) => {
console.error(err);
});
app.use(express.json());
app.use("/api/auth", authRoute);
app.use("/api/users", userRoute);
app.use("/api/lists", listRoute);
app.use("/api/movies", movieRoute);
app.use(express.static(path.join(__dirname, "/client/build")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "/client/build", "index.html"));
});
app.listen(process.env.PORT || 8800, () => {
console.log("Backend server is running!");
});