-
Notifications
You must be signed in to change notification settings - Fork 20
Read Application Creds from a json locale file. #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can pass an object with the shape of a I'm not sure how it would work to read environment variables for your VCAP_SERVICES, since it's not the easiest value to be setting as an env var. I guess I'd like to see a somewhat thorough use case of using > 1 service, each having > 1 property in the services' |
Thank you for your response. Actually my issue was that I was able to use all the services connected to my application through credentials stored in a local JSON file. But when I push the application to Bluemix it just continues to crash because I couldn't get the credentials. After reading your IBM page : https://developer.ibm.com/bluemix/2014/10/14/keeping-secrets-cloud-application-access-credentials-private-data/ I finally came up with this code, mixing the use of //loading credentials from file
nconf.file('local-settings.json');
//loading
var appEnv = cfenv.getAppEnv();
//local configuration
if(nconf.get("applicationSecret")){
config = {
applicationRoute : nconf.get("applicationRoute"),
applicationId : nconf.get("applicationId"),
applicationSecret: nconf.get("applicationSecret")
};
}else { // prod configuration
config = appEnv.getServiceCreds(/session-secret/);
} Now, when I run the server in my local machine I can use the Bluemix services like I am not sure that this is the best way to do so ? but it works just fine. |
Given the code you've provided, if you ever accidently include cfenv includes a property in the appEnv object returned by Another option is to shape your var localVCAP = null
try { localVCAP = require("./local-vcap.json") } catch(e) {}
var appEnv = cfenv.getAppEnv({vcap: localVCAP}) The Here's an example of a JSON file for your |
Understood. Thank you for all these tips ! |
closing as I believe this has been resolved |
Hi,
I've been using nconf module and one of the greatest things is that you can read some parameters from a file and if the file doesn't exists, read from environment variables like this :
nconf.file('local-settings.json').env();
Is it possible to add this to cfenv ? or it already exists ?
Thank you.
The text was updated successfully, but these errors were encountered: