-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (50 loc) · 1.45 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
57
58
59
60
61
62
63
64
const express = require("express");
const { default: mongoose } = require("mongoose");
const session = require("express-session");
const redis = require("redis");
const cors = require("cors");
let RedisStore = require("connect-redis")(session);
const {
MONGO_USER,
MONGO_PASSWORD,
MONGO_IP,
MONGO_PORT,
REDIS_URL,
REDIS_PORT,
SESSION_SECRET
} = require("./config/config");
let redisClient = redis.createClient({
host: REDIS_URL,
port: REDIS_PORT,
}
);
const postRouter = require("./routes/postRoutes");
const userRouter = require("./routes/userRoutes");
const app = express()
const mongoDBURL = `mongodb://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_IP}:${MONGO_PORT}/test?authSource=admin`;
mongoose
.connect(mongoDBURL)
.then(() => console.log("Successfully connected to DB"))
.catch((e) => console.log(e))
app.enable("trust proxy");
app.use(cors({}));
app.use(session({
store: new RedisStore({client: redisClient}),
secret: SESSION_SECRET,
cookie: {
secure: false,
resave: false,
saveUninitialized: false,
httpOnly: false,
maxAge: 30000,
}
}));
app.use(express.json());
app.get("/api/v1", (req, res) => {
res.send("<h2>Hi There!!!WatchTower working!!!</h2>");
console.log("Yeah it ran")
} )
app.use("/api/v1/posts", postRouter);
app.use("/api/v1/users", userRouter);
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`lisening on port ${port}`))