-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
46 lines (36 loc) · 1.05 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require("express");
const cors = require("cors");
const path = require("path");
const createError = require("http-errors");
const app = express();
app.use(express.json());
const corsOptions = { origin: process.env.URL || "*" };
app.use(cors(corsOptions));
//if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "client/build")));
//}
app.get("/api", (req, res) => {
res.send("🚀 Server running 🚀");
});
app.use("/api/auth", require("./routes/auth"));
app.use("/api/dashboard", require("./routes/dashboard"));
app.use("/api/todos", require("./routes/todos"));
app.use((req, res, next) => {
next(createError(404, "Not found"));
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send({
error: {
status: err.status || 500,
message: err.message,
},
});
});
const PORT = process.env.PORT || 5000;
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client/build/index.html"));
});
app.listen(PORT, () => {
console.log("Running on port 5000");
});