-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (41 loc) · 1.22 KB
/
index.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
import DBCONNECT from './database/index.js'
import authRoute from './routes/auth.js'
import cookieParser from 'cookie-parser'
import cors from 'cors'
import dotenv from 'dotenv'
import express from 'express'
import hotelsRoute from './routes/hotels.js'
import roomsRoute from './routes/rooms.js'
import usersRoute from './routes/users.js'
const corsOptions ={
origin: true,
credentials:true, //access-control-allow-credentials:true
optionSuccessStatus:200
}
dotenv.config();
const PORT = process.env.PORT || 3000;
const APP = express();
APP.use(cors(corsOptions));
// MIDDLEWARES
APP.use(express.json());
APP.use(cookieParser());
APP.use('/hotels', hotelsRoute);
APP.use('/rooms', roomsRoute);
APP.use('/users', usersRoute);
APP.use('/auth', authRoute);
// error handling MIDDLEWARE
APP.use((err, req, res, next) => {
console.log("Middleware Error Hadnling");
const errStatus = err.statusCode || 500;
const errMsg = err.message || 'Something went wrong';
res.status(errStatus).json({
success: false,
status: errStatus,
message: errMsg,
stack: err.stack
})
})
APP.listen(PORT, () =>{
DBCONNECT();
console.log(`Server is running on port ${PORT} 🚀...`);
})