diff --git a/README.md b/README.md index d985705..eb1f557 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,9 @@ The `options` parameter is optional, and can contain the following properties: This option property is ignored if not running locally. -This function returns an object with the following properties: +#### return value + +The `getAppEnv()` function returns an object with the following properties: * `app`: object version of `VCAP_APPLICATION` env var * `services`: object version of `VCAP_SERVICES` env var diff --git a/lib-src/cfenv.coffee b/lib-src/cfenv.coffee index 4082ef4..0252bd5 100644 --- a/lib-src/cfenv.coffee +++ b/lib-src/cfenv.coffee @@ -166,7 +166,10 @@ getServices = (appEnv, options) -> #------------------------------------------------------------------------------- getPort = (appEnv) -> - portString = process.env.PORT || process.env.CF_INSTANCE_PORT || process.env.VCAP_APP_PORT || appEnv?.app?.port + portString = process.env.PORT || + process.env.CF_INSTANCE_PORT || + process.env.VCAP_APP_PORT || + appEnv?.app?.port unless portString? return 3000 unless appEnv.name? diff --git a/tests/fixtures/vcap-local-good.json b/tests/fixtures/vcap-local-good.json index efc2dc6..1590ec6 100644 --- a/tests/fixtures/vcap-local-good.json +++ b/tests/fixtures/vcap-local-good.json @@ -1,4 +1,7 @@ { + "application": { + "port": 42 + }, "services": { "service-a-label": [ { diff --git a/tests/test-core.coffee b/tests/test-core.coffee index 1fbdf4f..8612edd 100644 --- a/tests/test-core.coffee +++ b/tests/test-core.coffee @@ -252,6 +252,7 @@ describe "appEnv", -> creds = appEnv.getServiceCreds "service-a" creds = JSON.stringify(creds) expect(creds).to.be '{"url":"foo"}' + expect(appEnv.port).to.be 42 #------------------------------------------- vcapFile = path.join(__dirname, 'fixtures', 'vcap-local-bad.json')