从中间件访问环回configuration数据

假设我们在Loopback中间件中,比如

app.use(function(req,res,next){ // I am not sure what key to use here in the getter... const config = app.get('?'); }); 

我想访问Loopback正在使用的整体configuration。

我试过了:

 const config = app.get('config'); const config = app.get('env'); const config = app.get('datasources'); 

没有任何东西给我相当我想要的。

有趣的是,这给了我:

 console.log(app.get('restApiRoot')); => '/api' 

所以这是一个线索到底是怎么回事,但我想获得上述数据的父对象。

我们怎样才能访问Loopback已经加载的configuration。 当然configuration因环境variables等而异

我想logging什么datasources.x.js文件被加载,什么config.x.js文件被加载,以及我可以捕获的任何其他服务器configuration信息。

解决如何做到这一点有很多麻烦。

这似乎是我有同样的问题: https : //github.com/strongloop/loopback/issues/1526

但他们指出我是谷歌集团的空白,我在那里search,找不到这个问题的答案。

这种行为实际上是从Expressinheritance的。

整个configuration存储在app.settings对象中, app.get(key)app.set(key,value)只是作为getter / setter。

console.log(app.settings); (例如在server/server.js中),它在一个新鲜的环回安装返回以下内容:

 { 'x-powered-by': true, etag: 'weak', 'etag fn': [Function: wetag], env: 'development', 'query parser': 'extended', 'query parser fn': [Function: parseExtendedQueryString], 'subdomain offset': 2, 'trust proxy': false, 'trust proxy fn': [Function: trustNone], view: [Function: View], views: 'C:\\Users\\*******\\Documents\\GitHub\\lbtest\\views', 'jsonp callback name': 'callback', host: '0.0.0.0', port: 3000, restApiRoot: '/api', remoting: { context: { enableHttpContext: false }, rest: { normalizeHttpPath: false, xml: false }, json: { strict: false, limit: '100kb' }, urlencoded: { extended: true, limit: '100kb' }, cors: false, errorHandler: { disableStackTrace: false } }, legacyExplorer: false, 'loopback-component-explorer': { mountPath: '/explorer' }, url: 'http://localhost:3000/' }