Skip to content

Commit 3d38525

Browse files
committed
use localhost as url hostname if uris not available
also * checking new Diego port env var CF_INSTANCE_PORT * added CODE_OF_CONDUCT.md * split out hacking bit from README.md into CONTRIBUTING.md
1 parent 5a78de3 commit 3d38525

File tree

8 files changed

+147
-43
lines changed

8 files changed

+147
-43
lines changed

CODE_OF_CONDUCT.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Contributor Code of Conduct
2+
================================================================================
3+
4+
As contributors and maintainers of this project, and in the interest of
5+
fostering an open and welcoming community, we pledge to respect all people who
6+
contribute through reporting issues, posting feature requests, updating
7+
documentation, submitting pull requests or patches, and other activities.
8+
9+
We are committed to making participation in this project a harassment-free
10+
experience for everyone, regardless of level of experience, gender, gender
11+
identity and expression, sexual orientation, disability, personal appearance,
12+
body size, race, ethnicity, age, religion, or nationality.
13+
14+
Examples of unacceptable behavior by participants include:
15+
16+
* The use of sexualized language or imagery
17+
* Personal attacks
18+
* Trolling or insulting/derogatory comments
19+
* Public or private harassment
20+
* Publishing other's private information, such as physical or electronic
21+
addresses, without explicit permission
22+
* Other unethical or unprofessional conduct.
23+
24+
Project maintainers have the right and responsibility to remove, edit, or reject
25+
comments, commits, code, wiki edits, issues, and other contributions that are
26+
not aligned to this Code of Conduct. By adopting this Code of Conduct, project
27+
maintainers commit themselves to fairly and consistently applying these
28+
principles to every aspect of managing this project. Project maintainers who do
29+
not follow or enforce the Code of Conduct may be permanently removed from the
30+
project team.
31+
32+
This code of conduct applies both within project spaces and in public spaces
33+
when an individual is representing the project or its community.
34+
35+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
36+
reported by opening an issue or contacting one or more of the project
37+
maintainers.
38+
39+
This Code of Conduct is adapted from the
40+
[Contributor Covenant](http://contributor-covenant.org),
41+
version 1.2.0, available at
42+
<http://contributor-covenant.org/version/1/2/0/>

CONTRIBUTING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Contributing
2+
================================================================================
3+
4+
Awesome! I'm happy that you want to contribute.
5+
6+
Make sure that you're read and understand the [Code of Conduct](CODE_OF_CONDUCT.md).
7+
8+
9+
Building from source
10+
--------------------------------------------------------------------------------
11+
12+
If you want to modify the source to play with it, you'll also want to have the
13+
`jbuild` program installed.
14+
15+
To install `jbuild`, use the command
16+
17+
```text
18+
npm -g install jbuild
19+
```
20+
21+
The `jbuild` command runs tasks defined in the `jbuild.coffee` file. The
22+
task you will most likely use is `watch`, which you can run with the
23+
command:
24+
25+
```text
26+
jbuild watch
27+
```
28+
29+
When you run this command, the application will be built from source, the server
30+
started, and tests run. When you subsequently edit and then save one of the
31+
source files, the application will be re-built, the server re-started, and the
32+
tests re-run. For ever. Use Ctrl-C to exit the `jbuild watch` loop.
33+
34+
You can run those build, server, and test tasks separately. Run `jbuild`
35+
with no arguments to see what tasks are available, along with a short
36+
description of them.
37+
38+
39+
GitHub usage
40+
--------------------------------------------------------------------------------
41+
42+
* Develop major features on feature branches, and submit PRs to `master`.
43+
44+
* Never force push onto `master`.
File renamed without changes.

README.md

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ If not set, the functions run in "local" mode, otherwise they run in "cloud"
1212
mode.
1313

1414

15-
1615
quick start
1716
================================================================================
1817

@@ -31,7 +30,6 @@ This code snippet above will get the port, binding host, and full URL to your HT
3130
server and use them to bind the server and print the server URL when starting.
3231

3332

34-
3533
running in Cloud Foundry vs locally
3634
================================================================================
3735

@@ -48,14 +46,12 @@ it will provide useful values when you're running in Cloud Foundry AND
4846
when you're running locally.
4947

5048

51-
5249
api
5350
================================================================================
5451

5552
The `cfenv` package exports the following function:
5653

5754

58-
5955
`getAppEnv(options)`
6056
--------------------------------------------------------------------------------
6157

@@ -126,6 +122,8 @@ is running locally, and `https:` otherwise; you can
126122
force a particular protocol by using the `protocol` property
127123
on the `options` parameter.
128124

125+
When running in Cloud Foundry, the `url` and `urls` values will have
126+
`localhost` as their hostname, if the actual hostnames cannot be determined.
129127

130128

131129
AppEnv methods
@@ -303,39 +301,14 @@ Next, push the app with `cf push`.
303301
When you visit the site, you'll see the output of various cfenv calls.
304302

305303

306-
307-
hacking
304+
changes
308305
================================================================================
309306

310-
If you want to modify the source to play with it, you'll also want to have the
311-
`jbuild` program installed.
312-
313-
To install `jbuild` on Windows, use the command
314-
315-
npm -g install jbuild
316-
317-
To install `jbuild` on Mac or Linux, use the command
307+
**1.0.3** - 2014/10/02
318308

319-
sudo npm -g install jbuild
309+
- fixes for compatibility with Diego - [issue #11][]
320310

321-
The `jbuild` command runs tasks defined in the `jbuild.coffee` file. The
322-
task you will most likely use is `watch`, which you can run with the
323-
command:
324-
325-
jbuild watch
326-
327-
When you run this command, the application will be built from source, the server
328-
started, and tests run. When you subsequently edit and then save one of the
329-
source files, the application will be re-built, the server re-started, and the
330-
tests re-run. For ever. Use Ctrl-C to exit the `jbuild watch` loop.
331-
332-
You can run those build, server, and test tasks separately. Run `jbuild`
333-
with no arguments to see what tasks are available, along with a short
334-
description of them.
335-
336-
337-
changes
338-
================================================================================
311+
[issue #11]: https://github.com/cloudfoundry-community/node-cfenv/issues/11
339312

340313
**1.0.2** - 2014/09/29
341314

@@ -344,15 +317,18 @@ changes
344317

345318
**1.0.1** - 2014/09/29
346319

347-
- remove node_modules from .cfignore - [issue #8](https://github.com/cloudfoundry-community/node-cfenv/issues/8)
320+
- remove node_modules from .cfignore - [issue #8][]
348321
- updated package dependencies
349322
- changed README.md to correct sample service to cf-env-test
350323
- files in lib/ recompiled due to coffee-script update
351324

325+
[issue #8]: https://github.com/cloudfoundry-community/node-cfenv/issues/8
326+
352327
**1.0.0** - 2014/09/03
353328

354329
- initial 1.0.0 release
355330

331+
356332
license
357333
================================================================================
358334

lib-src/cfenv.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ getServices = (appEnv, options) ->
142142

143143
#-------------------------------------------------------------------------------
144144
getPort = (appEnv) ->
145-
portString = process.env.VCAP_APP_PORT || process.env.PORT
145+
portString = process.env.PORT || process.env.CF_INSTANCE_PORT || process.env.VCAP_APP_PORT
146146

147147
unless portString?
148148
return 3000 unless appEnv.name?
@@ -193,7 +193,7 @@ getURLs = (appEnv, options) ->
193193

194194
else
195195
unless uris?
196-
throwError "expecting VCAP_APPLICATION to contain uris when not runninng locally"
196+
uris = [ "localhost" ]
197197

198198
protocol = options.protocol
199199

lib/cfenv.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cfenv",
33
"main": "./lib/cfenv",
44
"description": "easy access to your Cloud Foundry application environment",
5-
"version": "1.0.2",
5+
"version": "1.0.3",
66
"author": "pmuellr",
77
"license": "Apache-2.0",
88
"homepage": "https://github.com/cloudfoundry-community/node-cfenv",

tests/test-core.coffee

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,59 @@ describe "appEnv", ->
404404
expect(fn).to.throwError /invalid PORT value:/
405405

406406
#-----------------------------------------------------------------------------
407-
it "error - missing uris", ->
407+
it "Diego - use localhost in url", ->
408408

409+
# VCAP_APPLICATION with no uris/uri in it
409410
vcapApplication =
410411
name: SampleName
411412
host: "sample-host"
412413

413414
process.env.VCAP_APPLICATION = JSON.stringify vcapApplication
414415

415-
fn = -> appEnv = cfenv.getAppEnv()
416-
console.log "expecting an error printed below:"
417-
expect(fn).to.throwError /expecting VCAP_APPLICATION to contain uris when not runninng locally/
416+
appEnv = cfenv.getAppEnv()
417+
418+
expect(appEnv.isLocal).to.be false
419+
expect(appEnv.urls.length).to.be 1
420+
expect(appEnv.url).to.be "https://localhost"
421+
422+
#-----------------------------------------------------------------------------
423+
it "env PORT", ->
424+
vcapApplication =
425+
name: SampleName
426+
host: "sample-host"
427+
428+
process.env.VCAP_APPLICATION = JSON.stringify vcapApplication
429+
process.env.PORT = "4000"
430+
431+
appEnv = cfenv.getAppEnv()
432+
433+
expect(appEnv.port).to.be 4000
434+
435+
#-----------------------------------------------------------------------------
436+
it "env CF_INSTANCE_PORT", ->
437+
vcapApplication =
438+
name: SampleName
439+
host: "sample-host"
440+
441+
process.env.VCAP_APPLICATION = JSON.stringify vcapApplication
442+
process.env.CF_INSTANCE_PORT = "4001"
443+
444+
appEnv = cfenv.getAppEnv()
445+
446+
expect(appEnv.port).to.be 4001
447+
448+
#-----------------------------------------------------------------------------
449+
it "env VCAP_APP_PORT", ->
450+
vcapApplication =
451+
name: SampleName
452+
host: "sample-host"
453+
454+
process.env.VCAP_APPLICATION = JSON.stringify vcapApplication
455+
process.env.VCAP_APP_PORT = "4002"
456+
457+
appEnv = cfenv.getAppEnv()
458+
459+
expect(appEnv.port).to.be 4002
418460

419461
#-------------------------------------------------------------------------------
420462
SampleVCAPServices_1 =

0 commit comments

Comments
 (0)