-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (33 loc) · 1.15 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
const path = require("path");
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cors = require("cors");
const dotenv = require("dotenv");
const morgan = require("morgan");
const colors = require("colors");
const authRoute = require("./routes/auth");
const postRoute = require("./routes/posts");
const TransactionPost = require("./routes/transaction");
const connectDB = require("./config/db");
dotenv.config();
const port = process.env.PORT || 5000
// connec to database
connectDB();
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
if (process.env.NODE_ENV === 'development') {
app.use(morgan("dev"))
}
app.use("/api/v1", authRoute);
app.use("/api/v1/posts", postRoute);
app.use("/api/v2/", TransactionPost);
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
app.get('*', (req, res) =>
res.sendfile(path.resolve(__dirname, 'client', 'build', 'index.html'))
)
}
app.listen(port, () => console.log(`Server running in ${process.env.NODE_ENV} mode on port ${port}`.yellow.bold));