all files / server/ application-express.js

100% Statements 1/1
50% Branches 3/6
100% Functions 0/0
100% Lines 1/1
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                                                       
'use strict'
 
import express from 'express'
import { join as joinPaths } from 'path'
import bodyParser from 'body-parser'
import methodOverride from 'method-override'
import morgan from 'morgan'
import expressControllerV1 from './controller-express-v1'
 
// application
const application = express()
const assetsPath = joinPaths(__dirname, 'assets')
application.set('port', process.env.PORT || 3000)
 
// middlewares
application.use(express.static(assetsPath))
application.use(bodyParser.urlencoded({ extended: true }))
application.use(methodOverride((req) => req.body._method)) // https://www.npmjs.com/package/method-override#override-using-a-query-value
 
// logger
Iif (application.get('env') !== 'test') {
  application.use(morgan(application.get('env') === 'development' ? 'dev' : 'combined'))
}
 
// api routes & middlewares
application.use('/v1', expressControllerV1)
 
export default application