-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
47 lines (44 loc) · 1.23 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
require('dotenv').config()
const fastify = require('fastify')()
const port = process.env.SERVER_PORT || 3000
fastify
.register(require('fastify-swagger'), {
routePrefix: '/documentation',
swagger: {
info: {
title: 'Fastify Basic Project',
description: 'API Overview',
version: '0.1.0'
},
host: `localhost:${port}`,
tags: [
{ name: 'User', description: 'User related end-points' }
],
schemes: ['http'],
consumes: ['application/json'],
produces: ['application/json'],
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'Authorization',
in: 'header'
}
}
},
exposeRoute: true
})
.register(require('fastify-helmet'))
.register(require('fastify-mongoose'), {
uri: process.env.MONGODB_URI
}, err => {
if (err) throw err
})
.register(require('./schemas/user'))
.register(require('fastify-auth'))
.register(require('./auth/jwt-auth'))
.register(require('./routes/userRoutes'), { prefix: '/users' })
.register(require('./routes/indexRoutes'))
fastify.listen(port, function (err) {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})