forked from poonam-kumawat/zest-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
43 lines (38 loc) · 1.33 KB
/
index.ts
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
import dotenv from "dotenv";
import express, { Express, Request, Response } from "express";
import cors from "cors";
import { connectToMongo } from "./conn";
import productRouter from "./routes/productRoute";
import categoryRouter from "./routes/categoryRoute";
import emailRouter from "./routes/userRoutes";
import userRouter from "./routes/userRoutes";
import { authorize } from "./middleware/authorize";
import pincodeRouter from "./routes/pincodeRoute";
import addressRouter from "./routes/addressRoute";
import paymentRouter from "./routes/paymentRoute";
dotenv.config();
connectToMongo();
const app: Express = express();
const port = process.env.PORT;
const allowedOrigins = [
"http://localhost:3000",
"https://zest-organic.vercel.app",
];
const options: cors.CorsOptions = {
origin: allowedOrigins,
};
app.use(express.static("public"));
app.use(cors(options));
app.use(express.json());
app.use("/api/product", productRouter);
app.use("/api/category", categoryRouter);
app.use("/api/user", userRouter);
app.use("/api/pincode", pincodeRouter);
app.use("/api/address", authorize, addressRouter);
app.use("/api/payment", authorize, paymentRouter);
app.get("/", (req: Request, res: Response) => {
res.send("Zest Backend running");
});
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});