Comments (14)
In a plain json configuration file, it's impossible to tell if the developers' intention is 1, 2, 3, or 4 unless we introduce extra meta, in which case, the config file will become a diff/patch. IMO, overriding the whole value is a reasonable solution as long as we document it.
from loopback-boot.
IMO, overriding the whole value is a reasonable solution as long as we document it.
In my opinion, the most frequent use-case for complex values is customising datasource configuration. In which case it makes more sense to add/override key-values instead of replacing the whole object.
Example: to specify different MySQL settings for the production environment, one wants to add or change host, port, username and password. Other options (e.g. connnector: mysql
) remain without change.
If we are going to support only one of 1-4, then I would definitely like to get more feedback from the community before making the decision.
from loopback-boot.
I'm fine with merging
too.
See https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/utils.js#L138. We use it to merge model settings.
from loopback-boot.
Can we reuse this merge function from datasource-juggler to be used in loopback-boot for nested objects? If so, I can try to make this work, just need to know where to start looking for where in the loopback code this should go. Im guessing its somewhere in the executor or config-loader.js files.
from loopback-boot.
I am using this one-level merging trick, it's not ideal but works for my usecase
matejc@4c88a5d
from loopback-boot.
@bajtos What's your take? We need a solution.
from loopback-boot.
@bajtos What's your take? We need a solution.
How about supporting two flavours of datasources.*.js
files:
-
a file exporting a config object (i.e. a dynamic version of
*.json
), only value-type values are supported (no change from the current state) -
a file exporting a function that will be called to modify the config object (a new feature)
module.exports = function(config) { config.mail.transports = [{ // configure SMTP }]; switch (config.db.connector) { case 'mysql': config.db.host = process.env.MYSQL_HOST; config.db.port = process.env.MYSQL_PORT; break; } // etc. });
That way we don't have to worry whether the JSON format is expressing the intention (merge/replace) clearly, and the users can apply whatever changes they need.
from loopback-boot.
So far when I attempt to change some variables (for ex, the password) like this I am having to do:
config.datasources.db.connector.settings.password = process.env.MY_PASS;
config.datasources.db.settings.password = process.env.MY_PASS;
Is this correct? It does not seem to work for me /: It is the correct spot where the password is stored but when using the DB, loopback fails with:
{
"error": {
"name": "Error",
"status": 500,
"message": "ER_ACCESS_DENIED_ERROR: Access denied for user 'starchup'@'localhost' (using password: YES)",
"stack": "Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'starchup'@'localhost' (using password: YES)\n at Handshake.Sequence._packetToError (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)\n at Handshake.ErrorPacket (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Handshake.js:101:18)\n at Protocol._parsePacket (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:271:23)\n at Parser.write (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Parser.js:77:12)\n at Protocol.write (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:39:16)\n at Socket.<anonymous> (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Connection.js:82:28)\n at Socket.EventEmitter.emit (events.js:107:17)\n at readableAddChunk (_stream_readable.js:159:16)\n at Socket.Readable.push (_stream_readable.js:126:10)\n at TCP.onread (net.js:514:20)\n --------------------\n at Protocol._enqueue (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:135:48)\n at Protocol.handshake (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:52:41)\n at PoolConnection.connect (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Connection.js:109:18)\n at Pool.getConnection (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Pool.js:42:23)\n at MySQL.query (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/lib/mysql.js:167:10)\n at MySQL.all (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-connector-mysql/lib/mysql.js:580:8)\n at Function.find (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback-datasource-juggler/lib/dao.js:735:34)\n at Function.ACL.checkAccessForContext (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback/lib/models/acl.js:397:8)\n at Function.Model.checkAccess (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback/lib/models/model.js:281:12)\n at Function.<anonymous> (/home/jeff/Dropbox/Starchup/dev/starchup-central/node_modules/loopback/lib/application.js:319:13)",
"code": "ER_ACCESS_DENIED_ERROR",
"errno": 1045,
"sqlState": "28000",
"fatal": true,
"INVALID_EXPRESSION_ERR": 51,
"TYPE_ERR": 52
}
}
Please advise,
THanks!
from loopback-boot.
@glesage connector gets the settings object from datasource settings.
// server/datasources.local.js
module.exports = {
"db" : {
"password": process.env.MY_PASS
}
}
from loopback-boot.
oh alright thks, works perfect indeed (:
from loopback-boot.
Have you guys considered using https://github.com/lorenwest/node-config instead of rolling your own, or at least as a base? It supports hierarchical configurations (something I needed to have loopback-passport working properly in multiple environments.)
from loopback-boot.
Have you guys considered using https://github.com/lorenwest/node-config instead of rolling your own, or at least as a base?
We did not investigate this option thoroughly. At the first glance, node-config does provide a fine-grained control over how the configs from different sources are merged.
It supports hierarchical configurations (something I needed to have loopback-passport working properly in multiple environments.)
loopback-boot supports hierarchical configurations too. Can you provide an example of what you are not able to achieve with our current solution?
from loopback-boot.
#52 implements a solution where both Object and Array values from .json
files are recursively merged together.
from loopback-boot.
The feature is available as of v2.1.0
.
from loopback-boot.
Related Issues (20)
- Subfolders in boot folder HOT 7
- [forward-port] Fix resolution of middleware modules
- Boot scripts are loaded, but not actually run HOT 9
- organizing configuration files leads to problems HOT 3
- test failing on browserify due to form-data HOT 1
- Document refactored design of loopback-boot HOT 1
- datasources duplicated when booting using a config HOT 1
- models not loaded when using config on boot HOT 1
- 3.0.0
- Async boot scripts - silent failure with security risk HOT 6
- resolveAppScriptPath() is not pass scriptExtensions to fixFileExtensions() HOT 2
- [BUG] Middleware is loading .js.map of .js HOT 1
- The middleware "loopback#static" in phase "files"is not defined in the main config
- Async operations in component initialization HOT 3
- isomorphic and uglify causing "AssertionError: must provide a valid {{SharedClass}}" HOT 1
- custom middleware not found when boot options are just __dirname HOT 2
- Why next() requires to trigger process.nextTick in bootscript. HOT 2
- export-api-def doesn't work with loopback-boot@3 HOT 1
- Address usage of config/application on boot LBOptions HOT 2
- Loopback-boot updating to 3.3.1 producting "LoopBack server listening @ https://undefined:undefined/" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-boot.