Node.js 在单独的路由文件中访问server.app.db时出现问题
我的问题是:如何在路由文件逻辑区域内访问我的Node.js 在单独的路由文件中访问server.app.db时出现问题,node.js,hapijs,Node.js,Hapijs,我的问题是:如何在路由文件逻辑区域内访问我的server.app.db 我已将我的路线放入单独的文件中,即用户、国家/地区。 每个路由文件如下所示 'use strict'; module.exports = [ { method: 'GET', path: '/user', config: { auth: 'simple', plugins: {'hapiAuthorization': {role: '...'}}, handle
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 = databaseConnection;
如果我试图从路由文件的逻辑区域访问server.app.db,我的应用程序就会挂起
问题不在于数据库本身,我连接到它时,server.js文件中没有出现问题。您需要像这样访问对象
request.server.app.db
文档还解释了请求的全部属性我的回答有帮助吗?是的,有帮助,很抱歉回复太晚。