-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
62 lines (44 loc) · 1.46 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import express from "express";
import cors, { CorsOptions } from "cors";
import userRouter from "./routes/userRouter";
import productRouter from "./routes/productRouter";
import utilsRouter from "./routes/utilsRouter";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import helmet from "helmet";
import xss from "xss-clean";
import rateLimit from "express-rate-limit";
import dotenv from "dotenv";
import globalErrorHandler from "./errors/errorController";
import paymentRouter from "./routes/paymentRouter";
dotenv.config({ path: __dirname + "/.env" });
const corsOptions: CorsOptions = {
origin: "http://localhost:3000",
};
const app = express();
app.use(cors());
app.use("/api", paymentRouter);
app.use(bodyParser.json());
// app.use(helmet());
// app.use(xss());
app.use(cookieParser());
// const limiter = rateLimit({
// windowMs: 15 * 60 * 1000,
// max: 100,
// standardHeaders: true,
// legacyHeaders: false,
// });
// app.use("/api", limiter);
app.use("/api/v1/user", userRouter);
app.use("/api/v1/product", productRouter);
app.use("/api/v1/utils", utilsRouter);
app.use("/", (req, res) => {
res.end("This is our Base URL , please try diffrent /api routes !");
});
app.all("*", (req, res, next) => {
next(new Error(` Can't find ${req.originalUrl} on this server!`));
});
app.use(globalErrorHandler);
app.listen(8000, () => {
console.log(`[server]: Server is running at http://localhost: 8000}`);
});