-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (45 loc) · 1.39 KB
/
Copy pathindex.js
File metadata and controls
55 lines (45 loc) · 1.39 KB
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
const express = require("express");
const mongoose = require("mongoose");
const session = require("express-session");
const MongoStore = require("connect-mongo");
const { MONGO_USER, MONGO_PASSWORD, MONGO_IP, MONGO_PORT } = require("./config/config");
const boulderRouter = require("./routes/boulderRoutes");
const userRouter = require("./routes/userRoutes");
const app = express();
const mongoURL = `mongodb://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_IP}:${MONGO_PORT}/?authSource=admin`;
const connectWithRetry = () => {
mongoose
.connect(mongoURL)
.then(() => {
console.log("connected to the DB");
app.use(
session({
secret: "unsecreto",
resave: false,
saveUninitialized: true,
store: MongoStore.create({ mongoUrl: mongoURL }),
cookie: {
secure: false,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24,
sameSite:"lax"
},
})
);
})
.catch((e) => {
console.log("error connecting to the DB", e);
setTimeout(connectWithRetry, 5000);
});
};
connectWithRetry();
app.use(express.json());
app.get("/", (req, res) => {
res.send("boulder?");
});
app.use("/api/v1/boulders", boulderRouter);
app.use("/api/v1/users", userRouter);
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});