Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guydumais/a55e66074fc010f6433be078e456be1f to your computer and use it in GitHub Desktop.
Save guydumais/a55e66074fc010f6433be078e456be1f to your computer and use it in GitHub Desktop.
...
// Next.js libraries
import Document, { Html, Head, Main, NextScript } from 'next/document'
// Next Strict Content Security Policy
import { NextStrictCSP } from 'next-strict-csp'
...
// Enable Head Strict CSP in production mode only
const HeadCSP = process.env.NODE_ENV === 'production' ? NextStrictCSP : Head
...
// Document component
class MyDoc extends Document {
render() {
return (
<Html>
<HeadCSP>
{ process.env.NODE_ENV === 'production' &&
<meta httpEquiv="Content-Security-Policy" />
}
...
</HeadCSP>
<body>
...
<Main />
<NextScript />
...
</body>
</Html>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment