首页 > 解决方案 > Express Handlebars 拒绝访问 mongoose 对象

问题描述

Express Handlebars 用于在我的应用程序中工作。使用我当前版本的软件包,车把和猫鼬之间似乎存在问题。一种解决方案可能是将 .lean() 放在我的猫鼬方法上。必须有更清洁的方法。任何解决方案的想法都值得赞赏?

错误:

Handlebars: Access has been denied to resolve the property "title" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:

当前安装的软件包:

  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "connect-flash": "^0.1.1",
    "express": "^4.16.4",
    "express-handlebars": "^3.0.0",
    "express-session": "^1.15.6",
    "method-override": "^3.0.0",
    "mongoose": "^5.3.13",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0"
  }

标签: node.jsmongodbmongoose-schemaexpress-handlebars

解决方案


在这里找到了解决方案:

https://github.com/handlebars-lang/allow-prototype-access#usage-express-handlebars-and-mongoose

安装允许原型访问

npm install @handlebars/allow-prototype-access

设置:

const Handlebars = require('handlebars')
const {allowInsecurePrototypeAccess} = require('@handlebars/allow-prototype-access')

app.engine('handlebars', expressHandlebars({
    handlebars: allowInsecurePrototypeAccess(Handlebars)
}));

推荐阅读