无法访问单独的路由文件中的server.app.db

我的问题是:如何在我的路由文件逻辑区域访问我的server.app.db

我已经把我的路线分成不同的文件,即。 用户,国家.. 每个路由文件看起来像这样。

 'use strict'; module.exports = [ { method: 'GET', path: '/user', config: { auth: 'simple', plugins: {'hapiAuthorization': {role: '...'}}, handler: function (request, reply) { // Logic - I need server.app.db to connect to the database. } } } //.. more routes ]; 

在我的server.js文件中,我保存了这样的数据库连接

  server.app.db = databaseConnection; 

如果我尝试从我的路由文件中的逻辑区域访问server.app.db我的应用程序只是挂起。

问题不是数据库本身,我已经连接到它没有问题从server.js文件。

你需要像这样访问对象

 request.server.app.db 

该文档还解释了请求对象的完整属性