-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (38 loc) · 1.27 KB
/
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
46
const express=require("express");
const parkingLotRouter=require("./router/parkingLotRouter");
const app=express();
const AppError=require("./utils/appError");
const errorController=require("./controller/errorController");
const userRouter=require("./router/userRouter");
const cookieParser=require("cookie-parser");
const reviewRouter=require("./router/reviewRouter");
const bookingsRouter=require("./router/bookingRouter");
const cors=require("cors")
app.use(express.static("./public"));
var whitelist = ['https://parkings.netlify.app', 'http://localhost:8080'];
var corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
},
credentials: true
}
app.use(cors(corsOptions))
app.use((req,res,next)=>{
console.log("Hey, I'm Middleware");
next();
})
app.use(express.json({limit: "10kb"}));
app.use(cookieParser());
app.use("/api/v1/parking-lots",parkingLotRouter);
app.use("/api/v1/users",userRouter);
app.use("/api/v1/reviews",reviewRouter);
app.use("/api/v1/bookings",bookingsRouter);
app.all("*",(req,res,next)=>{
next(new AppError(`${req.originalUrl} is not defined on this server`,404));
})
app.use(errorController);
module.exports=app;