从中间件访问环回配置数据

Accessing Loopback config data from middleware

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

app.use(function(req,res,next){

    // I am not sure what key to use here in the getter...
    const config = app.get('?');

});

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

我试过了:

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

没有什么能满足我的需求。

有趣的是,这给了我:

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

所以这是发生了什么的线索,但我想获取上述数据的父对象。

我们如何访问Loopback加载的配置。配置当然因环境变量等而异

我想记录加载了哪些 datasources.x.js 文件和加载了哪些 config.x.js 文件,以及我可以捕获的任何其他服务器配置信息。

在弄清楚如何执行此操作时遇到了很多麻烦。

这似乎与我的问题相同: https://github.com/strongloop/loopback/issues/1526

但他们将我指向 Google 组的空白,我在那里搜索但找不到这个问题的答案。

这种行为实际上是继承自Express

整个配置存储在 app.settings 对象中,app.get(key)app.set(key,value) 只是充当 getter/setter。

console.log(app.settings);(例如,在 server/server.js 中)在新的环回安装 returns 上执行以下操作:

{ '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/' }