1 | require 'colors'
|
2 | _proxy = require('json-proxy')
|
3 | _ = require 'lodash'
|
4 | _router = require './router'
|
5 | _utils = require './utils'
|
6 | _initialize = require './initialize'
|
7 |
|
8 |
|
9 | module.exports = (app, server, startServer)->
|
10 |
|
11 | cfgProxy = _utils.config.proxy || {}
|
12 | cfgProxy.headers = _.extend cfgProxy.headers || {}, headers: 'X-Forwarded-User': 'Silky'
|
13 | app.use _proxy.initialize(proxy: cfgProxy)
|
14 |
|
15 |
|
16 | _router(app)
|
17 |
|
18 |
|
19 | return if not startServer
|
20 | app.set 'port', _utils.options.port || _utils.config.port || 14422
|
21 | server.on 'error', (err) ->
|
22 | if err.code is 'EADDRINUSE'
|
23 | console.log "端口冲突,请使用其它端口".red
|
24 | return process.exit(1)
|
25 |
|
26 | console.log "Silky发生严重错误".red
|
27 | console.log err.message.red
|
28 |
|
29 | server.listen app.get('port')
|
30 | console.log "Port -> #{app.get('port')}"
|
31 | console.log "Workbench -> #{_utils.options.workbench}"
|
32 | console.log "Environment -> #{_utils.options.env}"
|
33 | console.log "Please visit http://localhost:#{app.get('port')}"
|
34 |
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
\ | No newline at end of file |