-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (31 loc) · 894 Bytes
/
server.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
const colors = require("colors");
const connectDB = require("./src/config/db");
const dotenv = require("dotenv");
const express = require("express");
// Load env vars
dotenv.config({ path: "./src/config/config.env" });
// Connect to database
connectDB();
// Route files
const sentences = require("./src/routes/sentences");
const users = require("./src/routes/users");
const votes = require("./src/routes/votes");
const cors = require("cors");
const app = express();
// Enable CORS
app.use(cors());
// Trust proxy
app.set("trust proxy", true);
// Body parser
app.use(express.json());
// Mount routers
app.use("/api/v1/sentences", sentences);
app.use("/api/v1/users", users);
app.use("/api/v1/votes", votes);
const PORT = process.env.PORT || 5000;
const server = app.listen(
PORT,
console.log(
`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`.yellow.bold
)
);