forked from octoblu/endo-podio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.coffee
48 lines (40 loc) · 1.84 KB
/
command.coffee
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
_ = require 'lodash'
MeshbluConfig = require 'meshblu-config'
path = require 'path'
Endo = require 'endo-core'
OctobluStrategy = require 'endo-core/octoblu-strategy'
MessageHandler = require 'endo-core/message-handler'
ApiStrategy = require './src/api-strategy'
MISSING_SERVICE_URL = 'Missing required environment variable: ENDO_PODIO_SERVICE_URL'
MISSING_MANAGER_URL = 'Missing required environment variable: ENDO_PODIO_MANAGER_URL'
MISSING_APP_OCTOBLU_HOST = 'Missing required environment variable: APP_OCTOBLU_HOST'
class Command
getOptions: =>
throw new Error MISSING_SERVICE_URL if _.isEmpty process.env.ENDO_PODIO_SERVICE_URL
throw new Error MISSING_MANAGER_URL if _.isEmpty process.env.ENDO_PODIO_MANAGER_URL
throw new Error MISSING_APP_OCTOBLU_HOST if _.isEmpty process.env.APP_OCTOBLU_HOST
meshbluConfig = new MeshbluConfig().toJSON()
apiStrategy = new ApiStrategy process.env
octobluStrategy = new OctobluStrategy process.env, meshbluConfig
jobsPath = path.join __dirname, 'src/jobs'
return {
apiStrategy: apiStrategy
deviceType: 'endo:podio'
disableLogging: process.env.DISABLE_LOGGING == "true"
meshbluConfig: meshbluConfig
messageHandler: new MessageHandler {jobsPath}
octobluStrategy: octobluStrategy
port: process.env.PORT || 80
appOctobluHost: process.env.APP_OCTOBLU_HOST
serviceUrl: process.env.ENDO_PODIO_SERVICE_URL
userDeviceManagerUrl: process.env.ENDO_PODIO_MANAGER_URL
staticSchemasPath: process.env.ENDO_PODIO_STATIC_SCHEMAS_PATH
}
run: =>
server = new Endo @getOptions()
server.run (error) =>
throw error if error?
{address,port} = server.address()
console.log "Server listening on #{address}:#{port}"
command = new Command()
command.run()