forked from gitter-badger/floca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fuser.js
51 lines (39 loc) · 1.14 KB
/
Fuser.js
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
var Server = require('./lib/Server')
var configServices = require('./ConfigServices')
var async = require('async')
var Channeller = require('./lib/Channeller')
var Configurer = require('./lib/DefaultConfigurer')
function Fuser ( option ) {
this.option = option || {}
this.channeller = option.channeller || new Channeller()
configServices.add( Configurer.config( option.floca.appName ) ).argv().env().add( this.option )
this.config = configServices.config()
this.channeller.init( this.config )
}
var FuserProto = Fuser.prototype
FuserProto.start = function ( callbackFn ) {
var self = this
var calls = [
function (cb) {
self.server = new Server( self.config, self.channeller, cb )
},
function (cb) {
self.server.serve( cb )
}
]
async.series( calls, function (err, res) {
if ( err )
self.stop( callbackFn, err, res )
else if ( callbackFn )
callbackFn(null, res)
} )
}
FuserProto.stop = function ( callbackFn, err, res ) {
if ( err ) console.error( err )
if ( this.server )
this.server.close( callbackFn )
else if ( callbackFn )
callbackFn( err, res )
}
Fuser.Channeller = Channeller
module.exports = exports = Fuser