javascript - Meanjs 禁止错误

标签 javascript angularjs node.js meanjs yeoman-generator-angular

我是 AngularJs 的新手,下面是 Meanjs yo generator 创建的策略代码,为了学习目的创建了一个图书馆管理系统,我面临的问题是当我测试我的服务器代码时,即 API 通过浏览器 URL...我得到的结果是 http://localhost:3000/api/searchbooks/bookname/davincicode 作为 JSON 对象

但对于下面的网址,它给了我 {message: 'User is not authorized'}
http://localhost:3000/api/searchbooks/bookname/davincicode/bookName

exports.invokeRolesPolicies = function () {
  acl.allow([  
{
    roles: ['user'],
    allows: [{
      resources: '/api/searchbooks',
      permissions: ['get']
    }, {
      resources: '/api/searchbooks/bookname/:searchbookName',
      permissions: ['get']
    }]
},
{
   roles: ['user'],
   allows: [{
     resources: '/api/searchbooks/bookname',
     permissions: ['get']
   }, {
     resources: '/api/searchbooks/bookname/:searchbookName/:action',
     permissions: ['get']
   }]
}

])};

exports.isAllowed = function (req, res, next) {
  var roles = (req.user) ? req.user.roles : ['guest'];

  // If an Searchbook is being processed and the current user created it then allow any manipulation
  if (req.searchbook && req.user && req.searchbook.user && req.searchbook.user.id === req.user.id) {
    return next();
  }
  // Check for user roles
  acl.areAnyRolesAllowed(roles, req.route.path, req.method.toLowerCase(), function (err, isAllowed) {
    if (err) {
      // An authorization error occurred
      return res.status(500).send('Unexpected authorization error');
    } else {
      if (isAllowed) {
        // Access granted! Invoke next middleware
        return next();
      } else {
        return res.status(403).json({
          message: 'User is not authorized'
        });
      }
    }
  });
};

我检查了我的 Angular 色,它只是作为用户,无法在其他地方找到如此具体的问题,请帮助或提供一些指示。

最佳答案

我在路由部分弄错了问题: app.route('/api/searchbooks/bookname/:searchbookName/:actionValue').all(searchbooksPolicy.isAllowed) .get(searchbooks.read)
在策略 url 中,它的 action 并且我必须将 actionValue 作为参数名称。

所以传递不正确的参数名称是一个问题..

关于javascript - Meanjs 禁止错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48889676/

相关文章:

node.js - 在 typescript 中使用带有 Angular 6 的 Node 短 ID 模块

javascript - 两种方式绑定(bind)在具有嵌入范围的指令中不起作用

node.js - Firebase Functions npm install 总是卡住

node.js - 如何在所有文件的 express.js 4.x 上启用 CORS?

c# - 如何让 C# 与 Javascript 互操作?

javascript - 如何为 ASP.NET MVC 3 + Razor View 封装可重用的 "control"

javascript - 在我的代码中,我可以使用向上和向下箭头键,但由于某种原因,左右似乎不起作用

javascript - 单击时样式切换器跳转到页面顶部

javascript - 参数 ... 不是函数,未定义

node.js - 环回模型验证失败(异步行为)