Skip to content

Commit

Permalink
build csp meta ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercoms committed Jul 12, 2024
1 parent 5af2d6a commit a50f125
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion astro.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { shield } from "@kindspells/astro-shield";
import sentry from "@sentry/astro";
import AstroPWA from "@vite-pwa/astro";
import type { AstroIntegration } from "astro";
import { defineConfig } from "astro/config";
import { defineConfig, envField } from "astro/config";
import crypto from "node:crypto";
import fs from "node:fs";
import { resolve } from "node:path";
Expand Down Expand Up @@ -158,5 +158,14 @@ export default defineConfig({
globalRoutePriority: true,
contentCollectionCache: true,
contentCollectionJsonSchema: true,
env: {
schema: {
NONCE: envField.string({
context: "server",
access: "secret",
default: nonce,
}),
},
},
},
});
4 changes: 4 additions & 0 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
---
import { getSecret } from "astro:env/server";
const nonce = getSecret("NONCE");
---

<html lang="en-US" data-bs-theme="dark" transition:animate="none">
<slot />

<meta property="csp-nonce" nonce={nonce} />

<script>
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
document.addEventListener("astro:page-load", () => {
Expand Down

0 comments on commit a50f125

Please sign in to comment.