【问题标题】:Node-ACl throws uhandled rejection errorNode-ACl 抛出未处理的拒绝错误
【发布时间】:2023-03-03 23:03:01
【问题描述】:

我在我的 express 应用程序中使用 ACL 模块。在服务器启动时,我使用 acl.allow() 函数定义了一些角色及其权限。

但它会记录一个错误,说明未定义的拒绝类型。错误在使用错误参数进行回调时消失。但我不太确定是什么引发了错误以及应该如何处理。

我正在使用的 sn-p 代码是:

    var aclmodule = new acl(new acl.mongodbBackend(config.db.URL, "accesscontrol_"));
    aclmodule.allow([
    {
        roles:['rolea'],
        allows:[
            {resources:['a','b'], permissions:['*']}
        ]
    },
    {
        roles:['roleb','rolec'],
        allows:[
            {resources:['a'], permissions:['view']}
        ]
    },
    {
        roles:['rolec'],
        allows:[
            {resources:['o'], permissions:['view','edit']}
        ]
    }
]);

});

控制台中记录的错误是:

未处理的拒绝类型错误:未定义不是函数 在 D:\user\web\myapp-web\node_modules\acl\lib\mongodb-backend.js:119:15

at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.

js:607:21 在 D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async。 js:246:17 在迭代(D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\l ib\async.js:146:13) 在 async.eachSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module s\async\lib\async.js:162:9) 在 _asyncMap (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async \lib\async.js:245:13) 在 Object.mapSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module s\async\lib\async.js:228:23) 在 Object.async.series (D:\myapp\web\myapp-web\node_modules\acl\node_mod ules\async\lib\async.js:605:19) 在 Object.MongoDBBackend.end (D:\myapp\web\myapp-web\node_modules\acl\li b\mongodb-backend.js:35:11) 在 Object.tryCatcher (D:\myapp\web\myapp-web\node_modules\acl\node_modul es\bluebird\js\main\util.js:26:23) 在 Object.ret [as endAsync] (eval at (D:\myapp\web\myapp-web \node_modules\acl\node_modules\bluebird\js\main\promisify.js:163:12),

【问题讨论】:

    标签: javascript node.js express promise acl


    【解决方案1】:

    config.db.URL 是字符串吗?如果是这样,这就是您的错误的原因。它失败的那一行是(mongodb-backend.js):

    self.db.collection(... -- 表示.collection() 未定义。 (如果“self.db”只是一个字符串,这将是有意义的。)

    Node-acl 在创建新的mongodbBackend 时需要一个数据库实例,比如says in the docs——对于example

     mongoose.connection.on('connected', function() {
        var myAcl = new acl(new acl.mongodbBackend(mongoose.connection.db));
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 2020-03-22
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多