-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (33 loc) · 1.24 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
const express = require("express");
const cookieParser = require("cookie-parser")
const dotenv = require("dotenv").config();
const { errorHandler } = require("./middleware/errorMiddleware");
const connectDB = require("./config/db");
const cors = require('cors')
const path = require("path")
const port = process.env.PORT || 5000;
connectDB();
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser())
app.use(cors())
app.use("/api/user", require("./routes/userRoutes"));
app.use("/api/teams", require("./routes/teamRoutes"));
app.use("/api/projects", require("./routes/projectRoutes"));
app.use("/api/bugs", require("./routes/bugRoutes"));
app.use("/api/tasks", require("./routes/taskRoutes"));
app.use("/api/logs", require("./routes/logRoutes"));
app.use(errorHandler);
// Serve client
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "./frontend/build")));
app.get("*", (req, res) =>
res.sendFile(
path.resolve(__dirname, "./", "frontend", "build", "index.html")
)
);
} else {
app.get("/", (req, res) => res.send("Please set to production"));
}
app.listen(port, () => console.log(`Server started on port ${port}`));