Skip to content

Commit

Permalink
fix: merge locals JSON.stringify enumerable when mergeLocals=true
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Jul 20, 2018
1 parent a243b2b commit d9fa7f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Engine {
// egg-view engine mode, the locals had merged
if (engine) {
if (this.config.mergeLocals) {
return this.setCSRFLocals(ctx, locals);
return this.setLocals(ctx, locals);
}
}
// source locals, no merge locals
Expand All @@ -58,19 +58,19 @@ class Engine {
} else {
locals = Object.assign({}, { ctx, request: ctx.request, helper: ctx.helper }, sourceLocals);
}
[ 'ctx', 'request', 'helper' ].forEach(key => {
Object.defineProperty(locals, key, { enumerable: false });
});
// only data
return this.setCSRFLocals(ctx, locals);
return this.setLocals(ctx, locals);
}

setCSRFLocals(ctx, locals) {
setLocals(ctx, locals) {
// when csrf enable, set ctx csrf
const security = this.app.config.security;
if (security.csrf && security.csrf.enable) {
return Object.assign({}, { csrf: ctx.csrf }, locals);
locals = Object.assign({}, { csrf: ctx.csrf }, locals);
}
[ 'ctx', 'request', 'helper' ].forEach(key => {
Object.defineProperty(locals, key, { enumerable: false });
});
return locals;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "egg-view-vue-ssr",
"version": "3.1.1",
"version": "3.1.2",
"description": "vue server side render solution for egg",
"eggPlugin": {
"name": "vuessr"
Expand Down

0 comments on commit d9fa7f8

Please sign in to comment.