-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (53 loc) · 1.59 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
const express = require("express");
const app = express();
const cors = require("cors");
const mongoose = require("mongoose");
const path = require("path");
const limiter = require("./middleware/rateLimiter");
require("dotenv").config();
// middleware
app.use(express.json());
app.use(cors());
app.use(limiter);
// serve images
app.use(express.static("public"));
// routes
const imagesRoutes = require("./routes/images");
const categoriesRoutes = require("./routes/categories");
const charactersRoutes = require("./routes/characters");
const coursesRoutes = require("./routes/courses");
const cupsRoutes = require("./routes/cups");
const gameModesRoutes = require("./routes/gameModes");
const itemsRoutes = require("./routes/items");
const maximumSpeedsRoutes = require("./routes/maximumSpeeds");
const nonPlayablesRoutes = require("./routes/nonPlayables");
const rivalsRoutes = require("./routes/rivals");
app.use(
"/api/",
imagesRoutes,
categoriesRoutes,
charactersRoutes,
coursesRoutes,
cupsRoutes,
gameModesRoutes,
itemsRoutes,
maximumSpeedsRoutes,
nonPlayablesRoutes,
rivalsRoutes
);
app.get("/", async (req, res) => {
res.status(200).sendFile(path.join(__dirname, "/views/index.html"));
});
// mongodb
const uri = `mongodb+srv://${process.env.USER}:${process.env.PASSWORD}@cluster0.pug2uxj.mongodb.net/?retryWrites=true&w=majority`;
mongoose
.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Connected to DB"))
.catch(console.error);
// start the server
app.listen(4999, () => {
console.log("Server listening on port 4999");
});