node.js - 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"
}
解决方案
在这里找到了解决方案:
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)
}));
推荐阅读
- javascript - 固定菜单中的下拉菜单
- c# - 用 c# 编程 EV3
- angularjs - 如何使用量角器导航到网站中的页面而不是主页并在其中进行测试操作?
- raspberry-pi - 将任何 USB 密钥插头安装在同一文件夹中的 USB 端口上
- pyspark - 解析 pyarrow.parquet.ParquetDataset 对象的模式
- javascript - 在一个函数中执行多个函数
- excel - 修剪和字典不能一起工作
- c# - 当我点击 dataGridView 时,它说索引超出范围必须是非负数并且小于集合的大小
- angular - 指定要在 Angular 中使用的 NPM 模块平台
- ios - 将 12 位刻度转换为日期