-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (44 loc) · 1.04 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
52
53
#!/usr/bin/env node
const path = require('path')
const config = require('./config')
const fastify = require('fastify')()
// postgres connection
fastify.register(require('fastify-postgres'), {
connectionString: config.db
})
// compression - add x-protobuf
fastify.register(
require('fastify-compress'), {
customTypes: /^text\/|\+json$|\+text$|\+xml|x-protobuf$/
}
)
// cache
fastify.register(
require('fastify-caching'), {
privacy: 'private',
expiresIn: config.cache
}
)
// CORS
fastify.register(require('fastify-cors'))
// swagger
fastify.register(require('fastify-swagger'), {
exposeRoute: true,
swagger: config.swagger
})
// static documentation path
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'documentation')
})
// routes
fastify.register(require('fastify-autoload'), {
dir: path.join(__dirname, 'routes')
})
// Launch server
fastify.listen(config.port, function (err, address) {
if (err) {
console.log(err)
process.exit(1)
}
console.info(`Server listening on ${address}`)
})