Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

node.js - Express Handlebars denied access to mongoose object

Express Handlebars use to work in my app. With my current versions of packages, there seems to be an issue between handlebars and mongoose. One solution may be to put a .lean() on my mongoose methods. There must be a cleaner way. Any ideas of a resolution are appreciated?

Error:

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:

Currently installed packages:

  "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"
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found a solution here:

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

Install allow-prototype-access

npm install @handlebars/allow-prototype-access

Settings:

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...