Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cloudfoundry-community/node-cfenv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4c29ce1d1dbb65f89abe33b5325201dd2b8eb7c5
Choose a base ref
...
head repository: cloudfoundry-community/node-cfenv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fb0a2aab407bdfd01c6b275b0af952f08d3de000
Choose a head ref
  • 13 commits
  • 14 files changed
  • 7 contributors

Commits on Apr 18, 2018

  1. add support for vcapFile option

    fixes #31
    Patrick Mueller committed Apr 18, 2018
    Copy the full SHA
    3490eda View commit details

Commits on Feb 21, 2019

  1. Locally use the options to read the port

    Georgi Panayotov authored and Patrick Mueller committed Feb 21, 2019
    Copy the full SHA
    c6262a6 View commit details
  2. add test for local vcapFile port usage

    Patrick Mueller committed Feb 21, 2019
    Copy the full SHA
    b60ef7c View commit details
  3. Upgrade underscore version 1.9.x

    Signed-off-by: Dan Painter <dpainte7@ford.com>
    jonnynabors authored and Patrick Mueller committed Feb 21, 2019
    Copy the full SHA
    f8b0392 View commit details
  4. Stop using outdated manifest stanza; use random-route instead

    mogul authored and Patrick Mueller committed Feb 21, 2019
    Copy the full SHA
    1a730e3 View commit details
  5. version 1.2.0

    Patrick Mueller committed Feb 21, 2019
    Copy the full SHA
    a5dbceb View commit details

Commits on Mar 22, 2019

  1. Copy the full SHA
    3f19f12 View commit details

Commits on Mar 25, 2019

  1. version 1.2.1

    Patrick Mueller committed Mar 25, 2019
    Copy the full SHA
    6927628 View commit details

Commits on Mar 26, 2019

  1. handle ports race condition by returning 3000

    fixes #40
    
    This is a very simple to fix to the problem with ports where it
    will occaisonally throw an error:
    
    - hoodiehq-archive/node-ports#4
    
    The fix is to catch the error and use port 3000.  Not great, but should
    handle some cases where this was a problem.
    
    An alternate fix to try would be to try fetching the port again, probably
    in a loop (with some limit), in hopes of getting a value from ports.
    Patrick Mueller committed Mar 26, 2019
    Copy the full SHA
    b07a59e View commit details
  2. version 1.2.2

    Patrick Mueller committed Mar 26, 2019
    Copy the full SHA
    4103a3e View commit details

Commits on Jul 24, 2020

  1. Issue 45 Remove '.cfignore'

    Jenna Goldstrich committed Jul 24, 2020
    Copy the full SHA
    02bb92d View commit details
  2. version 1.2.3

    Co-authored-by: Jenna Goldstrich <jgoldstrich@pivotal.io>
    Jenna Goldstrich committed Jul 24, 2020
    Copy the full SHA
    63e072a View commit details

Commits on Apr 3, 2021

  1. update dependencies, now at version 1.2.4

    - upgrade most dependencies, but not CoffeeScript, since the latest
      version generates code that can't be run in older versions of node
    
    - change to call `yaml.load()` instead of `yaml.safeLoad()` since it's no
      longer supported, noticed via an error message:
    
      ```
      Error: Function yaml.safeLoad is removed in js-yaml 4. Use yaml.load instead, which is now safe by default.
      ```
    pmuellr committed Apr 3, 2021
    Copy the full SHA
    fb0a2aa View commit details
Showing with 223 additions and 58 deletions.
  1. +0 −3 .cfignore
  2. +1 −0 .gitignore
  3. +1 −0 .npmrc
  4. +7 −25 CONTRIBUTING.md
  5. +71 −2 README.md
  6. +2 −2 jbuild.coffee
  7. +31 −3 lib-src/cfenv.coffee
  8. +37 −5 lib/cfenv.js
  9. +1 −1 lib/server.js
  10. +1 −1 manifest.yml
  11. +22 −15 package.json
  12. +1 −0 tests/fixtures/vcap-local-bad.json
  13. +16 −0 tests/fixtures/vcap-local-good.json
  14. +32 −1 tests/test-core.coffee
3 changes: 0 additions & 3 deletions .cfignore

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
tmp
npm-debug.log
.vscode
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock = false
32 changes: 7 additions & 25 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
Contributing
================================================================================

Awesome! I'm happy that you want to contribute.
Awesome! We're happy that you want to contribute.

Make sure that you're read and understand the [Code of Conduct](CODE_OF_CONDUCT.md).


Building from source
--------------------------------------------------------------------------------

If you want to modify the source to play with it, you'll also want to have the
`jbuild` program installed.
The following `npm` scripts are available when doing development on this
package:

To install `jbuild`, use the command

```text
npm -g install jbuild
```

The `jbuild` command runs tasks defined in the `jbuild.coffee` file. The
task you will most likely use is `watch`, which you can run with the
command:

```text
jbuild watch
```

When you run this command, the application will be built from source, the server
started, and tests run. When you subsequently edit and then save one of the
source files, the application will be re-built, the server re-started, and the
tests re-run. For ever. Use Ctrl-C to exit the `jbuild watch` loop.

You can run those build, server, and test tasks separately. Run `jbuild`
with no arguments to see what tasks are available, along with a short
description of them.
* `npm run build` - build the library from the CoffeeScript source
* `npm run serve` - run a test server
* `npm test` - run the tests
* `npm run watch` - watch for source file changes, then `build`, then `test`


GitHub usage
73 changes: 71 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -43,7 +43,9 @@ your application is running in Cloud Foundry. These include:
If these aren't set, the `getAppEnv()` API will still return useful values,
as appropriate. This means you can use this package in your program and
it will provide useful values when you're running in Cloud Foundry AND
when you're running locally.
when you're running locally. You can supply local versions of
`VCAP_SERVICES` and/or `VCAP_APPLICATION` by using the `vcap` and `vcapFile`
options described below.


api
@@ -89,7 +91,19 @@ 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:
* `vcapFile` - provide the same function as the `vcap` option, but instead of
setting the option value to an object, you set it to the name of a JSON
file, which will be parsed and used as the `vcap` option value is used,
as described above.

When both `vcap` and `vcapFile` options are provided, the values in `vcap`
are ignored.

This option property is ignored if not running locally.

#### 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
@@ -311,6 +325,54 @@ When you visit the site, you'll see the output of various cfenv calls.
changes
================================================================================

**1.2.4** - 2021/04/03

- upgrade most dependencies, but not CoffeeScript, since the latest
version generates code that can't be run in older versions of node - [pr #50][]

- change to call `yaml.load()` instead of `yaml.safeLoad()` since it's no
longer supported, noticed via an error message: - [pr #50][]

```
Error: Function yaml.safeLoad is removed in js-yaml 4. Use yaml.load instead, which is now safe by default.
```

[pr #50]: https://github.com/cloudfoundry-community/node-cfenv/pull/50

**1.2.3** - 2020/07/24

- remove `.cfignore` file - [commit #02bb92d][]

[commit #02bb92d]: https://github.com/cloudfoundry-community/node-cfenv/commit/02bb92dacf5f59244b188dae11fd2fe732c4940e

**1.2.2** - 2019/03/26

- handle ports package race condition by returning port 3000 - [pr #41][]

[pr #41]: https://github.com/cloudfoundry-community/node-cfenv/pull/41

**1.2.1** - 2019/03/25

- upgrade js-yaml to avoid vulnerability - [pr #39][]

[pr #39]: https://github.com/cloudfoundry-community/node-cfenv/pull/39

**1.2.0** - 2019/02/21

- use vcapFile port value if available - [pr #36][]
- upgrade underscore from 1.8.x to 1.9.x - [pr #37][]
- use `random-route:` instead of `${random-word}` in sample manifest - [pr #38][]

[pr #36]: https://github.com/cloudfoundry-community/node-cfenv/pull/36
[pr #37]: https://github.com/cloudfoundry-community/node-cfenv/pull/37
[pr #38]: https://github.com/cloudfoundry-community/node-cfenv/pull/38

**1.1.0** - 2018/04/18

- add the `vcapFile` option - [issue #31][]

[issue #31]: https://github.com/cloudfoundry-community/node-cfenv/issues/31

**1.0.4** - 2017/01/13

- fix to getServiceURL() with non-http URLs - [issue #21][]
@@ -342,6 +404,13 @@ changes
- initial 1.0.0 release


contributing
================================================================================

See the [CONTRIBUTING.md](CONTRIBUTING.md) doc for more information on
contributing to this project.


license
================================================================================

4 changes: 2 additions & 2 deletions jbuild.coffee
Original file line number Diff line number Diff line change
@@ -68,8 +68,8 @@ tasks.test = ->
ui: "bdd"
reporter: "spec"
slow: 300
compilers: "coffee:coffee-script"
require: "coffee-script/register"
# compilers: "coffee:coffeescript"
require: "coffeescript/register"

options = for key, val of options
"--#{key} #{val}"
34 changes: 31 additions & 3 deletions lib-src/cfenv.coffee
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@ class AppEnv
catch
@isLocal = true

@_getVcapFromFile(options) if @isLocal

@app = getApp @, options
@services = getServices @, options

@@ -38,6 +40,26 @@ class AppEnv
@urls = getURLs @, options
@url = @urls[0]

#-----------------------------------------------------------------------------
_getVcapFromFile: (options) ->
return if not options?.vcapFile

contents = null
try
contents = fs.readFileSync options.vcapFile, 'utf8'
catch err
console.log "error reading vcapFile '#{options.vcapFile}': #{err}; ignoring"
return

vcap = null
try
vcap = JSON.parse contents
catch err
console.log "error parsing vcapFile '#{options.vcapFile}': #{err}; ignoring"
return

options.vcap = vcap

#-----------------------------------------------------------------------------
toJSON: ->
{@app, @services, @isLocal, @name, @port, @bind, @urls, @url}
@@ -144,12 +166,18 @@ getServices = (appEnv, options) ->

#-------------------------------------------------------------------------------
getPort = (appEnv) ->
portString = process.env.PORT || process.env.CF_INSTANCE_PORT || process.env.VCAP_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?

portString = "#{ports.getPort appEnv.name}"
try
portString = "#{ports.getPort appEnv.name}"
catch e
portString = '3000'

port = parseInt portString, 10
throwError "invalid PORT value: /#{portString}/" if isNaN port
@@ -165,7 +193,7 @@ getName = (appEnv, options) ->

if fs.existsSync "manifest.yml"
yString = fs.readFileSync "manifest.yml", "utf8"
yObject = yaml.safeLoad yString, filename: "manifest.yml"
yObject = yaml.load yString, filename: "manifest.yml"

yObject = yObject.applications[0] if yObject.applications?
return yObject.name if yObject.name?
42 changes: 37 additions & 5 deletions lib/cfenv.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
applications:
- name: cf-env-test
mem: 128M
host: cf-env-test-${random-word}
random-route: true
services:
- cf-env-test
37 changes: 22 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
{
"name": "cfenv",
"main": "./lib/cfenv",
"description": "easy access to your Cloud Foundry application environment",
"version": "1.0.4",
"author": "pmuellr",
"license": "Apache-2.0",
"homepage": "https://github.com/cloudfoundry-community/node-cfenv",
"name": "cfenv",
"main": "./lib/cfenv",
"description": "easy access to your Cloud Foundry application environment",
"version": "1.2.4",
"author": "pmuellr",
"license": "Apache-2.0",
"homepage": "https://github.com/cloudfoundry-community/node-cfenv",
"repository": {
"type": "git",
"url": "https://github.com/cloudfoundry-community/node-cfenv.git"
"type": "git",
"url": "https://github.com/cloudfoundry-community/node-cfenv.git"
},
"scripts": {
"build": "jbuild build",
"serve": "jbuild serve",
"test": "jbuild test",
"watch": "jbuild watch"
},
"dependencies": {
"js-yaml": "3.7.x",
"ports": "1.1.x",
"underscore": "1.8.x"
"js-yaml": "4.0.x",
"ports": "1.1.x",
"underscore": "1.12.x"
},
"devDependencies": {
"coffee-script": "1.12.x",
"mocha": "3.2.x",
"expect.js": "0.3.x"
"coffeescript": "1.12.x",
"expect.js": "0.3.x",
"jbuild": "1.0.x",
"mocha": "8.3.x"
}
}
1 change: 1 addition & 0 deletions tests/fixtures/vcap-local-bad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this file intentially does not contain valid JSON
16 changes: 16 additions & 0 deletions tests/fixtures/vcap-local-good.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"application": {
"port": 42
},
"services": {
"service-a-label": [
{
"name": "service-a",
"label": "service-a-label",
"credentials": {
"url": "foo"
}
}
]
}
}
Loading