UNPKG

991 BJavaScriptView Raw
1// Initialize nconf with proper config
2require('./nconf')
3
4const defaults = require('lodash/defaults')
5const path = require('path')
6const EventEmitter = require('events').EventEmitter
7const errorApp = require('./error')
8const server = require('./server')
9
10const ROOT_PATH = process.env.ROOT_PATH || process.cwd()
11
12module.exports = (options = {}, cb) => {
13 // Set project dir to process.cwd(). In future we may want to allow to
14 // allow the customization of this parameter.
15 options.dirname = ROOT_PATH
16
17 defaults(options, {
18 appRoutes: {},
19 publicPath: './public',
20 loginUrl: '/login',
21 websockets: true,
22 bodyParserLimit: '10mb',
23 error: errorApp
24 })
25
26 // Transform public path to be absolute
27 options.publicPath = path.resolve(options.dirname, options.publicPath)
28
29 // Run cb to setup additional options that require initialized nconf
30 // and do event handling
31 options.ee = new EventEmitter()
32 cb && cb(options.ee, options)
33
34 // Run app
35 server(options)
36}