-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (42 loc) · 1.3 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const pug = require("pug");
const path = require("path");
const morgan = require("morgan");
const colors = require("colour");
const connectDB = require("./src/config/db");
const errorHandlerMiddleware = require("./src/middlewares/errorHandlerMiddleware");
const app = express();
app.use(express.urlencoded({ extended: false }));
//Body parser
app.use(express.json());
// Route files
const authRoutes = require("./src/routes/auth");
const userRoutes = require("./src/routes/user");
const paystackRoutes = require("./src//routes/paystack");
//Dev logging middleware
if (process.env.NODE_ENV === "development") {
app.use(morgan("dev"));
}
// Enable CORS
app.use(cors());
// Set static folder
app.use(express.static(path.join(__dirname, "src/public/")));
app.set("views", path.join(__dirname, "src/views"));
app.set("view engine", "pug");
const PORT = process.env.PORT || 3000;
app.use("/api/v1/users", userRoutes);
app.use("/api/v1/auth", authRoutes);
app.use("/", paystackRoutes);
// Connect to mongo db
connectDB();
//Error handler middleware
app.use(errorHandlerMiddleware);
app.listen(
PORT,
console.log(
`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`.yellow.bold
)
);
module.exports = app;