all files / server/ application-hapi.js

100% Statements 2/2
50% Branches 1/2
100% Functions 6/6
100% Lines 2/2
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                                                                                                                                                                 
'use strict'
 
import config from 'config'
import { join as joinPaths } from 'path'
import Hapi from 'hapi'
import Hoek from 'hoek'
import Blipp from 'blipp'
import HapiMethodChange from 'hapi-method-change'
 
import hapiControllerV1 from './controller-hapi-v1'
 
class ApplicationHapi extends Hapi.Server {
  constructor (options) {
    super(options)
 
    let connection = config.get('myfox-wrapper-api.server.hapi.main-connection')
    Iif (process.env.PORT) {
      connection.port = process.env.PORT
    }
    this.connection(connection)
 
    // Logger
    const loggerOptions = {
      ops: {
        interval: 1000
      },
      reporters: {
        console: [{
          module: 'good-squeeze',
          name: 'Squeeze',
          args: [{ log: '*', response: '*' }]
        }, {
          module: 'good-console'
        }, 'stdout']
      }
    }
    this.register({
      register: require('good'),
      loggerOptions
    }, (err) => {
      Hoek.assert(!err, err)
    })
 
    // Method override
    this.register(HapiMethodChange, (err) => {
      // https://github.com/58bits/hapi-method-change#registering-the-plugin
      Hoek.assert(!err, err)
    })
 
    // Controller and routes
    this.register({register: hapiControllerV1}, {routes: {prefix: '/v1'}}, (err) => {
      Hoek.assert(!err, err)
    })
 
    // Assets path
    this.register(require('inert'), (err) => {
      Hoek.assert(!err, err)
    })
    this.route({
      method: 'GET',
      path: '/{param*}',
      handler: {
        directory: {
          path: joinPaths(__dirname, 'assets'),
          listing: false
        }
      }
    })
 
    // Blipp, for routes dump at startup time.
    this.register({
      register: Blipp, options: {
        showStart: true
      }
    }, (err) => {
      Hoek.assert(!err, err)
    })
  }
}
 
export default ApplicationHapi