feathers-configuration
Advanced tools
Comparing version 0.3.3 to 0.4.0
# Change Log | ||
## [v0.3.3](https://github.com/feathersjs/feathers-configuration/tree/v0.3.3) (2016-09-12) | ||
[Full Changelog](https://github.com/feathersjs/feathers-configuration/compare/v0.3.2...v0.3.3) | ||
## [v0.3.2](https://github.com/feathersjs/feathers-configuration/tree/v0.3.2) (2016-09-12) | ||
@@ -4,0 +7,0 @@ [Full Changelog](https://github.com/feathersjs/feathers-configuration/compare/v0.3.1...v0.3.2) |
import feathers from 'feathers'; | ||
import configuration from '../src'; | ||
let conf = configuration(); | ||
let app = feathers() | ||
.configure(configuration(__dirname)); | ||
.configure(conf); | ||
@@ -12,1 +14,2 @@ console.log(app.get('frontend')); | ||
console.log(app.get('templates')); | ||
console.log(conf()); |
@@ -7,9 +7,7 @@ 'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _fs = require('fs'); | ||
var _debug = require('debug'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _debug2 = _interopRequireDefault(_debug); | ||
@@ -20,22 +18,13 @@ var _path = require('path'); | ||
var _debug = require('debug'); | ||
var _debug2 = _interopRequireDefault(_debug); | ||
var _deepAssign = require('deep-assign'); | ||
var _deepAssign2 = _interopRequireDefault(_deepAssign); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var debug = (0, _debug2.default)('feathers:configuration'); | ||
var config = require('config'); | ||
var separator = _path2.default.sep; | ||
exports.default = module.exports = function (root) { | ||
var configFolder = arguments.length <= 1 || arguments[1] === undefined ? 'config' : arguments[1]; | ||
var deep = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; | ||
exports.default = module.exports = function () { | ||
return function () { | ||
return function () { | ||
var app = this; | ||
var env = app.settings.env; | ||
var convert = function convert(current) { | ||
@@ -59,3 +48,3 @@ var result = Array.isArray(current) ? [] : {}; | ||
// Make relative paths absolute | ||
value = _path2.default.resolve(_path2.default.join(root, configFolder), value.replace(/\//g, separator)); | ||
value = _path2.default.resolve(_path2.default.join(config.util.getEnv('NODE_CONFIG_DIR')), value.replace(/\//g, separator)); | ||
} | ||
@@ -71,19 +60,13 @@ } | ||
var config = convert(require(_path2.default.join(root, configFolder, 'default'))); | ||
var env = config.util.getEnv('NODE_ENV'); | ||
debug('Initializing configuration for ' + env + ' environment'); | ||
var conf = convert(config); | ||
var envConfig = _path2.default.join(root, configFolder, env); | ||
// We can use sync here since configuration only happens once at startup | ||
if (_fs2.default.existsSync(envConfig + '.js') || _fs2.default.existsSync(envConfig + '.json')) { | ||
config = deep ? (0, _deepAssign2.default)(config, convert(require(envConfig))) : _extends(config, convert(require(envConfig))); | ||
} else { | ||
debug('Configuration file for ' + env + ' environment not found at ' + envConfig); | ||
if (!app) { | ||
return conf; | ||
} | ||
Object.keys(config).forEach(function (name) { | ||
var value = config[name]; | ||
Object.keys(conf).forEach(function (name) { | ||
var value = conf[name]; | ||
debug('Setting ' + name + ' configuration value to', value); | ||
app.set(name, value); | ||
@@ -90,0 +73,0 @@ }); |
{ | ||
"name": "feathers-configuration", | ||
"description": "A small configuration module for your Feathers application.", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/feathersjs/feathers-configuration", | ||
@@ -38,3 +38,3 @@ "main": "lib/", | ||
"jshint": "jshint src/. test/. --config", | ||
"mocha": "NODE_ENV=testing mocha test/ --compilers js:babel-core/register", | ||
"mocha": "NODE_CONFIG_DIR=./test/config/ NODE_ENV=testing mocha test/ --compilers js:babel-core/register", | ||
"test": "npm run jshint && npm run mocha && nsp check" | ||
@@ -47,3 +47,3 @@ }, | ||
"debug": "^2.2.0", | ||
"deep-assign": "^2.0.0" | ||
"config": "^1.21.0" | ||
}, | ||
@@ -50,0 +50,0 @@ "devDependencies": { |
@@ -9,12 +9,10 @@ # feathers-configuration | ||
`feathers-configuration` allows you to load default and environment specific JSON configuration files and environment variables and set them on your application. Here is what it does: | ||
This release of `feathers-configuration` simply acts as a wrapped around [node-config](https://github.com/lorenwest/node-config). | ||
- Given a root and configuration path load a `default.json` in that path | ||
- When the `NODE_ENV` is not `development`, also try to load `<NODE_ENV>.json` in that path and merge both configurations | ||
- Go through each configuration value and sets it on the application (via `app.set(name, value)`). | ||
- If the value is a valid environment variable (e.v. `NODE_ENV`), use its value instead | ||
- If the value start with `./` or `../` turn it it an absolute path relative to the configuration file path | ||
- Both `default` and `<env>` configurations can be modules which provide their computed settings with `module.exports = {...}` and a `.js` file suffix. See `test/config/testing.js` for an example. | ||
All rules listed above apply for `.js` modules. | ||
By default this implementation will look in `config/*` for `default.json`. | ||
As per the [config docs](https://github.com/lorenwest/node-config/wiki/Configuration-Files) this is highly configurable. | ||
Future releases will also include adapters for external configuration storage. | ||
## Usage | ||
@@ -29,3 +27,3 @@ | ||
// Use the current folder as the root and look configuration up in `settings` | ||
let app = feathers().configure(configuration(__dirname, 'settings')) | ||
let app = feathers().configure() | ||
``` | ||
@@ -60,8 +58,10 @@ | ||
``` | ||
```js | ||
import feathers from 'feathers'; | ||
import configuration from 'feathers-configuration'; | ||
let conf = configuration(); | ||
let app = feathers() | ||
.configure(configuration(__dirname)); | ||
.configure(conf); | ||
@@ -73,2 +73,4 @@ console.log(app.get('frontend')); | ||
console.log(app.get('templates')); | ||
console.log(conf()); | ||
``` | ||
@@ -87,5 +89,12 @@ | ||
Or with a different environment and variables: | ||
Or via custom environment variables by setting them in `config/custom-environment-variables.json`: | ||
```js | ||
{ | ||
"port": "PORT", | ||
"mongodb": "MONGOHQ_URL" | ||
} | ||
``` | ||
``` | ||
PORT=8080 MONGOHQ_URL=mongodb://localhost:27017/production NODE_ENV=production node app | ||
@@ -99,2 +108,4 @@ // -> path/to/app/public/dist | ||
You can also override these variables with arguments. Read more about how with [node-config](https://github.com/lorenwest/node-config) | ||
## License | ||
@@ -101,0 +112,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
15
110
2
14015
81
+ Addedconfig@^1.21.0
+ Addedconfig@1.31.0(transitive)
+ Addedjson5@1.0.2(transitive)
+ Addedminimist@1.2.8(transitive)
- Removeddeep-assign@^2.0.0
- Removeddeep-assign@2.0.0(transitive)
- Removedis-obj@1.0.1(transitive)