-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (35 loc) · 958 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
36
37
38
import express from 'express';
import session from "express-session";
import cors from "cors";
import mongoose from "mongoose";
import UserRoutes from "./users/routes.js";
import "dotenv/config";
import MovieRoutes from "./movies/routes.js";
const app = express()
app.use(express.json());
app.use(
cors({
credentials: true,
origin: process.env.NODE_ENV === "production"
? process.env.FRONTEND_URL
: process.env.FRONTEND_URL_LOCAL,
})
);
const sessionOptions = {
secret: "any string",
resave: false,
saveUninitialized: false,
};
if (process.env.NODE_ENV !== "development") {
sessionOptions.proxy = true;
sessionOptions.cookie = {
sameSite: "none",
secure: true,
};
}
app.use(session(sessionOptions));
const CONNECTION_STRING = process.env.DB_CONNECTION_STRING;
mongoose.connect(CONNECTION_STRING);
UserRoutes(app);
MovieRoutes(app);
app.listen(process.env.PORT || 4000);