-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
35 lines (28 loc) · 985 Bytes
/
index.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
_ = require('underscore')
application = JSON.parse(process.env.VCAP_APPLICATION || "{}")
try
vcapServices = JSON.parse(process.env.VCAP_SERVICES)
catch err
vcapServices = {}
services = _.flatten(_.map(vcapServices, (svcs, t) -> svcs))
module.exports =
appName: application.name
port: process.env.VCAP_APP_PORT || process.env.PORT
instanceIndex: application.instance_index
services: services
application: application
vcapServices: vcapServices
getService: (name, credsOverride) ->
if credsOverride
if _.isString(credsOverride)
service = name: name, credentials: JSON.parse(credsOverride)
else
service = name: name, credentials: credsOverride
console.log "Using overrided credentials for service: " + name
else
service = _.find(services, (s) -> s.name.match name )
if service
console.log "Using service: " + service.name
else
console.error "Could not find service: " + name
service