-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
80 lines (68 loc) · 1.78 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const express = require("express");
const cors = require("cors");
const dotenv = require("dotenv");
const passport = require("passport");
const mongoose = require("mongoose");
const session = require("express-session");
// const cookieParser = require("cookie-parser");
dotenv.config();
const PORT = process.env.PORT;
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// app.use(express.static(__dirname));
// app.use(cookieParser());
app.use(
cors({
origin: process.env.FRONTEND_URL,
credentials: true,
})
);
app.set("trust proxy", 1);
let sess = {
secret: process.env.APP_SECRET,
resave: true,
saveUninitialized: true,
cookie: {
sameSite: "none",
secure: true,
maxAge: 1000 * 60 * 60 * 24 * 7, // One Week
},
// cookie: { }
};
// if(app.get('env') === "production"){
// // app.set('trust proxy', 1);
// sess.cookie.secure = true;
// sess.cookie.httpOnly = true;
// }
app.use(session(sess));
app.use(passport.initialize());
app.use(passport.session());
mongoose.connect(process.env.DATABASE, (e) => {
if (e) return e;
console.log("database connected successfully");
});
app.use((req, res, next) => {
req.requestTime = new Date();
next();
});
app.get("/", (req, res) => {
res.send("File Tracker");
});
const authRouter = require("./routes/authRouter");
const fileRouter = require("./routes/fileRouter");
const userRouter = require("./routes/userRouter");
app.use("/auth", authRouter);
app.use("/api/file", fileRouter);
app.use("/api/user", userRouter);
app.get("*", (req, res) => {
res.status(404).json({
status: "FAIL",
data: {
message: "Can't find this route in the server",
},
});
});
app.listen(PORT || 8800, (req, res) => {
console.log(`Server is running on ${PORT}`);
});