-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (32 loc) · 1.04 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
const express = require("express");
const cors = require("cors");
require("dotenv").config();
require("./db/conn");
const userRouter = require("./routes/userRoutes");
const itemRouter = require("./routes/itemRoutes");
const cartRouter = require("./routes/cartRoutes");
const paymentRouter = require("./routes/paymentRoutes");
const path = require("path");
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
app.use("/api/user", userRouter);
app.use("/api/item", itemRouter);
app.use("/api/cart", cartRouter);
app.use("/api/payment", paymentRouter);
app.use(express.static(path.join(__dirname, "./client/build")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
app.use((err, req, res, next) => {
const errStatus = err.status || 500;
const errMsg = err.message || "Something went wrong";
return res.status(errStatus).send({
success: false,
stack: err.stack,
message: errMsg,
status: errStatus,
});
});
app.listen(port, () => {});