-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (42 loc) · 1.14 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
const fs = require('fs')
const path = require('path')
// Require the fastify framework and instantiate it
const fastify = require('fastify')({
logger: true
})
/*
https: {
key: fs.readFileSync(path.join(__dirname, '.', 'https', 'ssl.key')),
cert: fs.readFileSync(path.join(__dirname, '.', 'https', 'ssl.crt'))
}
*/
// Require external modules
const mongoose = require('mongoose')
// Import Routes
const routes = require('./routes')
// Import Swagger Options
const swagger = require('./config/swagger')
// Import DB Connection
const db = require('./config/db_heroku');
// Register Swagger
fastify.register(require('fastify-swagger'), swagger.options)
// Connect to DB
mongoose.connect(db.url)
.then(() => console.log('MongoDB connected...'))
.catch(err => console.log(err))
// Loop over each route
routes.forEach((route, index) => {
fastify.route(route)
})
// Run the server!
const start = async () => {
try {
await fastify.listen(process.env.PORT || 3000, '0.0.0.0')
fastify.swagger()
fastify.log.info(`server listening on ${fastify.server.address().port}`)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
start()