-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (28 loc) · 955 Bytes
/
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
'use strict'
require('dotenv').load()
const debug = require('debug')('tommy-api:core')
const config = require('config')
const plugins = require('./src/plugins')(config)
const server = require('./src/server')(config)
const registerStatsdPlugin = () => {
const hapiStatsdConfig = {
host: config.get('statsd.host'),
port: config.get('statsd.port'),
prefix: config.get('statsd.prefix')
}
server.register({ register: require('hapi-statsd'), options: hapiStatsdConfig })
}
Promise.resolve()
.then(() => debug('Starting server'))
.then(() => {
if (config.get('statsd.enabled')) {
return registerStatsdPlugin()
}
})
.then(() => server.register(plugins.list, plugins.options))
.then(() => server.start())
.then(() => debug('Server running at:', server.info.uri))
.catch(err => {
console.log('server start error: ', err)
console.log(err.stack)
})