1 | expressOctoblu = require 'express-octoblu'
|
2 | MeshbluAuth = require 'express-meshblu-auth'
|
3 | Router = require './router'
|
4 | multer = require 'multer'
|
5 | debug = require('debug')('triggers-service:server')
|
6 |
|
7 | class Server
|
8 | constructor: (options)->
|
9 | { @logFn, @disableLogging, @port } = options
|
10 | { @meshbluConfig } = options
|
11 |
|
12 | address: =>
|
13 | @server.address()
|
14 |
|
15 | run: (callback) =>
|
16 | meshbluAuth = new MeshbluAuth @meshbluConfig
|
17 |
|
18 | app = expressOctoblu({ @logFn, @disableLogging, bodyLimit: '50mb' })
|
19 | app.use meshbluAuth.auth()
|
20 | app.use multer().any()
|
21 |
|
22 | router = new Router {@meshbluConfig, meshbluAuth}
|
23 | router.route app
|
24 |
|
25 | @server = app.listen @port, callback
|
26 |
|
27 | stop: (callback) =>
|
28 | @server.close callback
|
29 |
|
30 | module.exports = Server
|