Handlebars 4.6.0λΆν° ν νλ¦Ώμ λ μ΄μ νλ‘ν νμ μμ± λ° λ©μλμ μ‘μΈμ€ν μ μμ΅λλ€(κΈ°λ³Έκ°). λ Όμ, μ΄μ λ° κ·Όκ±°λ #1633μ μ°Έμ‘°νμμμ€.
μ΄μ λμμ 볡μνκ³ μ μ΄νλ ββλ°νμ μ΅μ μ΄ μμ§λ§(https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access μ°Έμ‘°), λμ νλ μμν¬λ₯Ό μ¬μ©νλ κ²½μ° νΈλ€λ° μ½μ΄μ κ²½μ° μ€μ λ°©λ²μ΄ λͺ ννμ§ μμ μ μμ΅λλ€.
μ΄ μ€λ₯ λ©μμ§κ° νμλλ©΄ λ€μ μ 보μ ν¨κ» μ견μ μΆκ°νμμμ€.
express-hbs
, express-handlebars
)κ° Handlebarsλ₯Ό νΈμΆν©λκΉ? (νμ€νμ§ μμ κ²½μ° npm ls handlebars
λλ yarn why handlebars
μ μΆλ ₯μ λΆμ¬λ£μ΅λλ€).Handlebars.compile
μ κ²°κ³Ό ν
νλ¦Ώ κΈ°λ₯μ μ§μ μ¬μ©νλ κ²½μ° https://handlebarsjs.com/api-reference/runtime-options.html#options -to-control-prototype-accessμ λ΅μ΄ μμ΄μΌ ν©λλ€. λ¬Έμκ° κ·νμ μ§λ¬Έμ λλ΅νμ§ μκ±°λ μ΄ν΄νμ§ λͺ»νλ κ²½μ° λ¬Έμλ₯Ό κ°μ ν μ μλλ‘ (μ¬κΈ°)μ λ¬Έμνμμμ€.express-handlebars
mongoose
Mongooseμ λͺ¨λΈμ ν΄λμ€μ΄λ©° μμ±μ μμ κ°μ²΄μ "μ체 μμ±"μ΄ μλλλ€.
κ°μ₯ κΉλν λ°©λ²μ νΈλ€λ° μ
λ ₯μ΄ μ μ ν μΌλ° μλ°μ€ν¬λ¦½νΈ κ°μ²΄μΈμ§ νμΈνλ κ²μ
λλ€. μ΄κ²μ toJSON()
λλ toObject
λ₯Ό νΈμΆνμ¬ Mongooseμμ μνν μ μμ΅λλ€.
app.get('/test', function (_req, res) {
Kitten.find({}).then(kittens => {
res.render('test.hbs', {
kittens: kittens.map(kitten => kitten.toJSON())
})
})
});
λ¬Έμμ μΈκΈλ runtimeOptions
(λλ templateOptions
)λ express-handlebars
μ€μ μ μ§μνμ§ μκΈ° λλ¬Έμ μ¬κΈ°μμ μ¬μ©ν μ μμ΅λλ€.
λΉ λ₯΄κ³ λλ¬μ΄ ν΄νΉ(μ λ§ ν΄νΉμ΄κ³ μ μνμ§ μμ)μ λ€μμ μ¬μ©νλ κ²μ λλ€.
var handlebarsInstance = Handlebars.create();
handlebarsInstance.compile = function (templateStr, compileOptions) {
// compile template
// return a function that calls the compiled template with `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options
// WARNING: People can crash your system by frabricating special templates. Don't use
// this if your users can create templates.
}
app.engine('hbs', expressHandlebars({
handlebars: handlebarsInstance
}));
Handlebars.createWithAllowedProtoAccess
λλ μ΄μ μ μ¬ν κ²μ μνμλ©΄ μ΄ λκΈμ λ‘μΌ μ΄λͺ¨ν°μ½μ μΆκ°νμΈμ.
μ΄ λ¬Έμ κ° μλλ° ν΄κ²° λ°©λ²μ λͺ¨λ₯΄κ² μ΅λλ€. λμμ£Όμκ² μ΅λκΉ?
νΈλ€λ°λ₯Ό μ¬μ©ν λ μ΄ μ€λ₯λ₯Ό μμ νλ λ°©λ²μ μλ €μ€ μ μλ μ¬λμ΄ μμ΅λκΉ?
μ€μ:
En-US: νΈλ€λ°: λΆλͺ¨μ "μμ μ μμ±"μ΄ μλκΈ° λλ¬Έμ μμ± "μ΄λ¦"μ νμΈνκΈ° μν μ‘μΈμ€κ° κ±°λΆλμμ΅λλ€.
νμΈ λλ μ΄ κ²½κ³ λ₯Ό λΉνμ±ννλ λ°νμ μ΅μ
μ μΆκ°ν μ μμ΅λλ€.
νΈλ€λ°λ₯Ό μ¬μ©ν λ μ΄ μ€λ₯λ₯Ό λ³΄κ³ νλ λ°©λ²μ μλ μ¬λμ΄ μμ΅λκΉ?
μ€μ:
En: νΈλ€λ°: "μ΄λ¦" μμ±μ μλ²μ§μ "μμ μ μμ±"μ΄ μλκΈ° λλ¬Έμ μ‘μΈμ€κ° κ±°λΆλμμ΅λλ€.
νμΈ λλ μ΄ κ²½κ³ λ₯Ό λΉνμ±ννλ λ°νμ μ΅μ μ μΆκ°ν μ μμ΅λλ€.
λ΄ κ²μ λ€μκ³Ό κ°μ΅λλ€.
const νΈλ€λ° = require('μ΅μ€νλ μ€ νΈλ€λ°')
app.engine('νΈλ€λ°', νΈλ€λ°({defaultLayout: 'λ©μΈ'}))
app.set('보기 μμ§', 'νΈλ€λ°')
app.get('/κ²°μ ', function(req, res){
Payment.findAll().then(ν¨μ(κ²°μ ){
res.render('κ²°μ ', {κ²°μ : κ²°μ })
})
κ°νλ₯Ό μ¬μ©νκ³ μΆμ΅λλ€. ~μ
κ°νλ₯Ό μ¬μ©νκ³ μΆμ΅λλ€. λΈ
μ΄κ²μ 보μμμ€: https://www.npmjs.com/package/@handlebars/allow -prototype-access
λ¬Έμμ μΈκΈλ
runtimeOptions
(λλtemplateOptions
)λexpress-handlebars
μ€μ μ μ§μνμ§ μκΈ° λλ¬Έμ μ¬κΈ°μμ μ¬μ©ν μ μμ΅λλ€.
express-handlebarsμμλ μ΄λ¬ν λ°νμ κ΅¬μ± μ΅μ μ μ€μ ν μ μκΈ° λλ¬Έμ express-handlebarsκ° νΈλ€λ° 4.5.3μ μ¬μ©νλλ‘ κ°μ νλ λ°©λ²μ μκ³ μλ μ¬λμ΄ μμ΅λκΉ?
https://www.npmjs.com/package/@handlebars/allow -prototype-accessλ₯Ό express-handlebars
μ ν¨κ» μ¬μ©ν μ μμ΅λλ€. κΈ°λ³Έ 맀κ°λ³μκ° μ€μ λλλ‘ μ»΄νμΌλ ν
νλ¦Ώμ λνν©λλ€.
Hi Nils, ν΄λΉ ν¨ν€μ§λ₯Ό μλμν¬ μ μμ΅λλ€. ν΄λΉ ν¨ν€μ§λ‘ μ€ννλ €κ³ νλ©΄ "μ€λ₯: "νΈλ€λ°" λͺ¨λμ΄ λ³΄κΈ° μμ§μ μ 곡νμ§ μμ΅λλ€."λΌλ λ©μμ§κ° λνλ©λλ€. μ€λ₯. λ€λ₯Έ μ¬μ©μκ° https://github.com/wycats/handlebars.js/issues/1648 μμ λΉμ·ν λ¬Έμ λ₯Ό κ²ͺκ³ μλ κ² κ°μ΅λλ€. κ°μ μ€λ λμ κ²°κ³Όλ₯Ό κ²μνμ΅λλ€. κ°μ¬ ν΄μ
@craj1031tx #1648μμ λ΅λ³λλ Έμ΅λλ€.
νλ μμν¬:
express-handlebars
mongoose
Mongooseμ λͺ¨λΈμ ν΄λμ€μ΄λ©° μμ±μ μμ κ°μ²΄μ "μ체 μμ±"μ΄ μλλλ€.
κ°μ₯ κΉλν λ°©λ²μ νΈλ€λ° μ λ ₯μ΄ μ μ ν μΌλ° μλ°μ€ν¬λ¦½νΈ κ°μ²΄μΈμ§ νμΈνλ κ²μ λλ€. μ΄κ²μ
toJSON()
λλtoObject
λ₯Ό νΈμΆνμ¬ Mongooseμμ μνν μ μμ΅λλ€.app.get('/test', function (_req, res) { Kitten.find({}).then(kittens => { res.render('test.hbs', { kittens: kittens.map(kitten => kitten.toJSON()) }) }) });
λ¬Έμμ μΈκΈλ
runtimeOptions
(λλtemplateOptions
)λexpress-handlebars
μ€μ μ μ§μνμ§ μκΈ° λλ¬Έμ μ¬κΈ°μμ μ¬μ©ν μ μμ΅λλ€.λΉ λ₯΄κ³ λλ¬μ΄ ν΄νΉ(μ λ§ ν΄νΉμ΄κ³ μ μνμ§ μμ)μ λ€μμ μ¬μ©νλ κ²μ λλ€.
var handlebarsInstance = Handlebars.create(); handlebarsInstance.compile = function (templateStr, compileOptions) { // compile template // return a function that calls the compiled template with `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options // WARNING: People can crash your system by frabricating special templates. Don't use // this if your users can create templates. } app.engine('hbs', expressHandlebars({ handlebars: handlebarsInstance }));
Handlebars.createWithAllowedProtoAccess
λλ μ΄μ μ μ¬ν κ²μ μνμλ©΄ μ΄ λκΈμ λ‘μΌ μ΄λͺ¨ν°μ½μ μΆκ°νμΈμ.
κ³ λ§μ μΉκ΅¬ :)
λλ λ‘μΌμ κ±°κΈ° λκ³ κ°λ€!
μ λ Sequelizeμ ν¨κ» Express-Handlebarsλ₯Ό μ¬μ©νκ³ μμ΅λλ€.
npm ls νΈλ€λ°:
+-- [email protected]
| `-- [email protected]
`-- [email protected]
μ½μ μΆλ ₯:
Handlebars: Access has been denied to resolve the property "name" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "id" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "email" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "url" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "description" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "createdAt" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "updatedAt" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
λλ λͺ½κ΅¬μ€μ λν λΉμ μ μ루μ μΌλ‘ λΉμ μ μνν΄ λ³Ό κ²μ λλ€
νλ μμν¬:
express-handlebars
mongoose
Mongooseμ λͺ¨λΈμ ν΄λμ€μ΄λ©° μμ±μ μμ κ°μ²΄μ "μ체 μμ±"μ΄ μλλλ€.
κ°μ₯ κΉλν λ°©λ²μ νΈλ€λ° μ λ ₯μ΄ μ μ ν μΌλ° μλ°μ€ν¬λ¦½νΈ κ°μ²΄μΈμ§ νμΈνλ κ²μ λλ€. μ΄κ²μ
toJSON()
λλtoObject
λ₯Ό νΈμΆνμ¬ Mongooseμμ μνν μ μμ΅λλ€.app.get('/test', function (_req, res) { Kitten.find({}).then(kittens => { res.render('test.hbs', { kittens: kittens.map(kitten => kitten.toJSON()) }) }) });
λ¬Έμμ μΈκΈλ
runtimeOptions
(λλtemplateOptions
)λexpress-handlebars
μ€μ μ μ§μνμ§ μκΈ° λλ¬Έμ μ¬κΈ°μμ μ¬μ©ν μ μμ΅λλ€.λΉ λ₯΄κ³ λλ¬μ΄ ν΄νΉ(μ λ§ ν΄νΉμ΄κ³ μ μνμ§ μμ)μ λ€μμ μ¬μ©νλ κ²μ λλ€.
var handlebarsInstance = Handlebars.create(); handlebarsInstance.compile = function (templateStr, compileOptions) { // compile template // return a function that calls the compiled template with `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options // WARNING: People can crash your system by frabricating special templates. Don't use // this if your users can create templates. } app.engine('hbs', expressHandlebars({ handlebars: handlebarsInstance }));
Handlebars.createWithAllowedProtoAccess
λλ μ΄μ μ μ¬ν κ²μ μνμλ©΄ μ΄ λκΈμ λ‘μΌ μ΄λͺ¨ν°μ½μ μΆκ°νμΈμ.
μλμ κ°μ΄ lean() λ©μλλ₯Ό μ¬μ©ν μλ μμ΅λλ€.
app.get('/test', function (_req, res) { Kitten.find().lean().then(kittens => res.render('test.hbs', { kittens: kittens})); });
express-handlebarsμμλ μ΄λ¬ν λ°νμ κ΅¬μ± μ΅μ μ μ€μ ν μ μκΈ° λλ¬Έμ express-handlebarsκ° νΈλ€λ° 4.5.3μ μ¬μ©νλλ‘ κ°μ νλ λ°©λ²μ μκ³ μλ μ¬λμ΄ μμ΅λκΉ?
μ΅μ€νλ μ€ νΈλ€λ°μ λ°νμ κ΅¬μ± μ΅μ μ μΆκ°ν μ μλλ‘ PRμ λ§λ€μμ΅λλ€. https://github.com/express-handlebars/express-handlebars/pull/53
κ°μ₯ μ μ©ν λκΈ
νλ μμν¬:
express-handlebars
mongoose
Mongooseμ λͺ¨λΈμ ν΄λμ€μ΄λ©° μμ±μ μμ κ°μ²΄μ "μ체 μμ±"μ΄ μλλλ€.
κ°μ₯ κΉλν λ°©λ²μ νΈλ€λ° μ λ ₯μ΄ μ μ ν μΌλ° μλ°μ€ν¬λ¦½νΈ κ°μ²΄μΈμ§ νμΈνλ κ²μ λλ€. μ΄κ²μ
toJSON()
λλtoObject
λ₯Ό νΈμΆνμ¬ Mongooseμμ μνν μ μμ΅λλ€.λ¬Έμμ μΈκΈλ
runtimeOptions
(λλtemplateOptions
)λexpress-handlebars
μ€μ μ μ§μνμ§ μκΈ° λλ¬Έμ μ¬κΈ°μμ μ¬μ©ν μ μμ΅λλ€.λΉ λ₯΄κ³ λλ¬μ΄ ν΄νΉ(μ λ§ ν΄νΉμ΄κ³ μ μνμ§ μμ)μ λ€μμ μ¬μ©νλ κ²μ λλ€.
Handlebars.createWithAllowedProtoAccess
λλ μ΄μ μ μ¬ν κ²μ μνμλ©΄ μ΄ λκΈμ λ‘μΌ μ΄λͺ¨ν°μ½μ μΆκ°νμΈμ.