1 |
|
2 | require('./nconf')
|
3 |
|
4 | const defaults = require('lodash/defaults')
|
5 | const path = require('path')
|
6 | const EventEmitter = require('events').EventEmitter
|
7 | const errorApp = require('./error')
|
8 | const server = require('./server')
|
9 |
|
10 | const ROOT_PATH = process.env.ROOT_PATH || process.cwd()
|
11 |
|
12 | module.exports = (options = {}, cb) => {
|
13 |
|
14 |
|
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 |
|
27 | options.publicPath = path.resolve(options.dirname, options.publicPath)
|
28 |
|
29 |
|
30 |
|
31 | options.ee = new EventEmitter()
|
32 | cb && cb(options.ee, options)
|
33 |
|
34 |
|
35 | server(options)
|
36 | }
|