Skip to content

Commit

Permalink
feat: 在 env中 提供 nonce 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
imsunhao committed Mar 20, 2019
1 parent 3a05ae2 commit 701a37b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ function makeLoginPageUrl(toPath: string) {
return newUrl
}

function getWindowEnv(renderEnv: string[]) {
function getWindowEnv(renderEnv: string[], nonce: string) {
const env = renderEnv.reduce(function(obj: any, key) {
obj[key] = process.env[key]
return obj
}, {})
env.VUE_ENV = 'client'
env.NONCE = nonce
return serialize(env, { isJSON: true })
}

Expand All @@ -54,7 +55,7 @@ function getContextHead(
: ''
const nonceStr = nonce ? `nonce="${nonce}"` : ''
return `<script ${nonceStr}>window.__INJECT_ENV__ = ${getWindowEnv(
req.renderEnv
req.renderEnv, nonce
)};window.__INJECT_CONTEXT__ = ${serialize(injectContext, {
isJSON: true
})}${autoRemove}</script>`
Expand Down

0 comments on commit 701a37b

Please sign in to comment.