Skip to content

Commit

Permalink
merge changes from #500 into #502
Browse files Browse the repository at this point in the history
  • Loading branch information
vejja committed Aug 2, 2024
1 parent 0e3ab07 commit b0b4a08
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"@types/node": "^18.18.1",
"eslint": "^8.50.0",
"nuxt": "^3.11.2",
"vitest": "^1.3.1",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"vitest": "^1.3.1"
},
"stackblitz": {
"installDependencies": false,
Expand Down
10 changes: 10 additions & 0 deletions playground/components/ServerComponent.server.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
<h1>Server-only Nuxt-Island component</h1>
<p>Nonce: <span id="server-nonce">{{ nonce }}</span></p>
</div>
</template>

<script setup lang="ts">
const nonce = useNonce()
</script>
6 changes: 6 additions & 0 deletions playground/pages/island.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
Island Page
<ServerComponent />
</div>
</template>
10 changes: 6 additions & 4 deletions src/runtime/nitro/plugins/60-recombineHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export default defineNitroPlugin((nitroApp) => {

// Let's insert the CSP meta tag just after the first tag which should be the charset meta
let insertIndex = 0
const metaCharsetMatch = html.head[0].match(/^<meta charset="(.*?)">/mdi)
if (metaCharsetMatch && metaCharsetMatch.indices) {
insertIndex = metaCharsetMatch.indices[0][1]
if (html.head.length > 0) {
const metaCharsetMatch = html.head[0].match(/^<meta charset="(.*?)">/mdi)
if (metaCharsetMatch && metaCharsetMatch.indices) {
insertIndex = metaCharsetMatch.indices[0][1]
}
html.head[0] = html.head[0].slice(0, insertIndex) + `<meta http-equiv="Content-Security-Policy" content="${headerValue}">` + html.head[0].slice(insertIndex)
}
html.head[0] = html.head[0].slice(0, insertIndex) + `<meta http-equiv="Content-Security-Policy" content="${headerValue}">` + html.head[0].slice(insertIndex)
}
})
})

0 comments on commit b0b4a08

Please sign in to comment.