-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (49 loc) · 1.46 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
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const userRoute = require("./Routes/userRoute");
const latestRoute = require("./Routes/latestRoute")
const popularRoute = require("./Routes/popularRoute")
const heroRoute = require("./Routes/heroRoute")
const newSeasonRoute = require("./Routes/newSeasonRoute")
const infoRoute = require("./Routes/infoRoute")
const app = express();
require("dotenv").config();
const serverTimeout = 60000
app.timeout = serverTimeout;
const originUri = process.env.ORIGIN_URI
const corsOptions = {
origin: [originUri, "http://localhost:5173", "http://localhost:5174"],
credentials: true,
};
// api route origin
app.use(express.json());
app.use(cors(corsOptions));
// user login, regsiter, admin right
app.use("/api/users", userRoute);
// rest api
app.use(
"/api/", latestRoute,
popularRoute,
heroRoute,
newSeasonRoute,
infoRoute
)
// root
app.get("/", (req, res) => {
res.send("Welcome to somadb!");
});
const port = process.env.PORT || 5000;
const uri = process.env.ATLAS_URI || 5000;
app.listen(port, (req, res) => {
console.log(`Server running on port: ${port}`);
});
mongoose
.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log("MongoDB connection establised");
})
.catch((error) => console.log("MongoDB Connection failed: ", error.message));