-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress.js
60 lines (49 loc) · 1.61 KB
/
express.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import express from "express";
import cors from "cors";
import cookieParser from "cookie-parser";
import dotenv from "dotenv";
import morgan from "morgan";
import path from "path";
import { connectWithDataBase } from "./mongoDB.js";
import authRouter from "./routes/auth.js";
import verifyTokenRouter from "./routes/tokenverify.js";
import verifyUser from "./middleware/verifyuser.js";
import productRouter from "./routes/product.js";
import paypalRouter from "./routes/paypal.js";
import userRouter from "./routes/user.js";
const __dirname = path.resolve();
const app = express();
const port = process.env.PORT || 5000;
// const dev = "http://localhost:5000";
// const baseURL =
// window.location.hostname.split(":")[0] === "localhost" ? dev : "";
dotenv.config();
connectWithDataBase();
app.use(morgan("dev"));
app.use(cookieParser());
app.use(express.json());
app.use(
cors({
origin: true,
credentials: true,
})
);
// The first request response which will gives fronntend to user
app.use("/", express.static(path.join(__dirname, "./web/build")));
// Authentication Routes
app.use("/api/v1/auth", authRouter);
// Product Routes
app.use("/api/v1/product", productRouter);
// token Verification Routes
app.use("/api/v1/tokenverify", verifyUser, verifyTokenRouter);
// Paypal Routes
app.use("/api/v1/paypal", verifyUser, paypalRouter);
// User Routes
app.use("/api/v1/user", verifyUser, userRouter);
app.use("/**", (req, res) => {
// res.redirect("/")
res.sendFile(path.join(__dirname, "./web/build/index.html"));
});
app.listen(port, () =>
console.log(`Example app listening on port http://localhost:${port}`)
);