-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (45 loc) · 1.1 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require('dotenv').config();
const cors = require('cors');
const cookieParser = require('cookie-parser');
const express = require('express');
const rateLimit = require('express-rate-limit')
const helmet = require("helmet")
const app = express();
const routes = require('./routes/index')
const base_url = process.env.BASE_URL
app.use(express.json({limit:'50mb'}));
// Database Connection
const connectDB = require('./database/connect');
//Middlewares
app.use(helmet());
app.use(cookieParser());
app.use(cors({
credentials: true,
origin: base_url,
sameSites: true,
secure: true
}));
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
limit: 100,
standardHeaders: 'draft-7',
legacyHeaders: false,
})
app.use(limiter)
// routes
app.get('/', (req, res) => {
res.send('<h1> Booking Api </h1>');
});
app.use('/api/', routes)
const port = process.env.PORT || 3000;
const start = async () => {
try {
await connectDB(process.env.MONGO_URL);
app.listen(port, () =>
console.log(`Server is listening on port ${port}...`)
);
} catch (error) {
console.log(error);
}
};
start();