-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (45 loc) · 1.12 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
const mongoose = require('mongoose')
const fastify = require('fastify')({
trustProxy: true,
logger: true,
})
const { dbConnection,port} = require('./Configs/generalConfiguration')
const SwaggerOptions = require('./Configs/swagger');
fastify.register(require('@fastify/swagger'),SwaggerOptions)
fastify.register(require('@fastify/helmet'))
fastify.register(require('@fastify/formbody'))
fastify.register(require('@fastify/rate-limit'),{
max: 1,
timeWindow: '600000',
hook: 'preHandler',
})
fastify.register(require('@fastify/cors'), {
origin: '*',
methods: ['GET', 'DELETE', 'PUT', 'POST'],
})
const routes = require('./Routes')
routes.map((allRoutes) => {
Object.keys(allRoutes).map((index) => {
allRoutes[index].map((route) => {
fastify.route(route);
})
})
})
mongoose.connect(
dbConnection,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => {
console.log('connected to db')
}
)
const start = async () => {
try {
await fastify.listen({ port: port })
fastify.swagger()
} catch (err) {
console.log(err)
fastify.log.error(err)
process.exit(1)
}
}
start()