Sails.js - access to local.js environment settings in controllers

In production , I have AWS credentials that are stored as heroku configuration variables.

In development I want to include configuration data in config / local.js, but how do I access configuration data in the controller?

local.js contains:

module.exports = { aws_key: "...", aws_secret: "..." }

In my controller, I tried aws_key , config.aws_key , and others - but no luck. Is there a main application namespace that I can use for scope in properties exported by local.js?

I am new to sails, and I feel that it should be straightforward - any help would be appreciated.

+8
javascript
source share
1 answer

Solution found. Step 3 was where I had problems.

TL; DR

I did not understand that module.exports.thing makes the thing object accessible through sails.config.thing . Good to know.


1) I created a new file in config / aws.js with the contents

 // Get heroku config values module.exports.aws = { key: process.env.AWS_KEY, secret: process.env.AWS_SECRET } 

2) . Actual AWS credits are placed in local.js (this will not be in the repository, since sails automatically ignore local.js using gitignore).

 aws: { key: actual-key, secret: actual-secret } 

This allows local testing when we do not have access to the hero configuration settings, while protecting these values ​​from exposure in the github registry.

3) Now, to access the controller:

 var aws_config = sails.config.aws; AWS.config.update({ accessKeyId: aws_config.key, secretAccessKey: aws_config.secret }); 

+30
source share

All Articles