-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
37 lines (31 loc) · 1.04 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
const express = require("express");
const app = express();
const cors = require("cors");
const mongoose = require("mongoose");
require("dotenv/config"); // Environment variables
// Route imports
const homeRoutes = require("./routes/home");
const authRoutes = require("./routes/auth");
const privateRoutes = require("./routes/privateRoutes");
const paginationExample = require("./routes/examples/paginationExample");
const limiter = require("./middlewares/rateLimiter");
// Constants
const EXAMPLES_ROUTE = "/api/examples";
// Middlewares
app.use(cors());
app.use(express.json());
app.use(limiter);
// -> Route Middlewares
app.use("/", homeRoutes);
app.use("/api/private", privateRoutes);
app.use("/api/user", authRoutes);
// -> Example Routes
app.use(`${EXAMPLES_ROUTE}/pagination`, paginationExample);
// Connect to Database
mongoose.connect(process.env.DB_URL, () => {
console.log("Connected to Database");
});
// Starting the server
app.listen(process.env.PORT, () => {
console.log(`Application running at http://localhost:${process.env.PORT}/`);
});