-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (40 loc) · 979 Bytes
/
app.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
import express from "express";
import errorMiddleware from "./middleware/error.js";
import cookieParser from "cookie-parser";
import fileUpload from "express-fileupload";
import expressSession from "express-session";
import cors from "cors";
export const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(
fileUpload({
useTempFiles: true,
})
);
app.use(
expressSession({
secret: "secret",
resave: false,
saveUninitialized: false,
})
);
//handle cors
app.use(
cors({
origin: `http://localhost:${process.env.PORT}`,
methods: ["GET", "POST", "PUT", "DELETE"],
credentials: true,
})
);
//Route Imports
import product from "./routes/ProductRoute.js";
import user from "./routes/UserRoute.js";
app.use("/api/v1", product);
app.use("/api/v1", user);
app.get("/", (req, res) => {
res.send("Hello World!");
});
//Middleware to handle errors
app.use(errorMiddleware);