-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (25 loc) · 810 Bytes
/
index.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
// Modules for express and cors
const express = require("express");
const app = express();
const cors = require("cors");
const pool = require("./db1");
const path = require("path");
const PORT = process.env.PORT || 5000;
// Middleware
// Connect React to Express
app.use(cors());
// Use req.body
app.use(express.json());
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "client/build")));
}
// Routes for todo-list
app.use("/todos", require("./routes/taskRoutes"));
app.use("/subtasks", require("./routes/subtaskRoutes"));
app.use("/filter", require("./routes/filterTasks"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.listen(PORT, () => {
console.log(`server has started on port ${PORT}`);
});