Skip to content

Commit

Permalink
docs(readme): update nonce Attribute section
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed May 6, 2024
1 parent e91eba5 commit f482170
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export default jsxRenderer(({ children }) => {

#### nonce Attribute

If you want to add a `nonce` attribute to `<Script />`, `<script />`, or `<style />` element, you can use [Security Headers Middleware](https://hono.dev/middleware/builtin/secure-headers).
If you want to add a `nonce` attribute to `<Script />` or `<script />` element, you can use [Security Headers Middleware](https://hono.dev/middleware/builtin/secure-headers).

Define the middleware:

Expand All @@ -322,14 +322,13 @@ Define the middleware:
import { createRoute } from 'honox/factory'
import { secureHeaders, NONCE } from 'hono/secure-headers'

export default createRoute(
secureHeaders({
contentSecurityPolicy: {
scriptSrc: [NONCE],
styleSrc: [NONCE],
},
})
)
secureHeaders({
contentSecurityPolicy: import.meta.env.PROD
? {
scriptSrc: [NONCE],
}
: undefined,
})
```

You can get the `nonce` value with `c.get('secureHeadersNonce')`:
Expand Down

0 comments on commit f482170

Please sign in to comment.