从中间件访问环回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/' }
- 环回MongoError:未授权在heroku_xxxx.role上进行查询
- StrongLoop:子表的ACL
- 无法杀死NodeJS应用程序
- Loopback.iorest连接器 – json发布不工作
- 通过Array进行迭代,asynchronous更新/创build对象,当一切完成时调用callback
- 使用loopback在URL中获取参数的远程方法
- 在MySQL Loopback Connector上执行原始查询
- 正确的方式来结合使用loopback.js路由和APIvalidation
- strongloop / loopback / heroku“inq”运算符在本地服务器上正常工作,但不在Heroku上