From f7d88a7d5ca9199f84fd8d9a5031c6f07c487519 Mon Sep 17 00:00:00 2001 From: adilallo <39313955+adilallo@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:51:55 -0700 Subject: [PATCH] Let Cloudron turn on named admins, the ops token, and Umami after the image is built. Tracker env is read at request time and the CSP already allows the analytics host, so staging can set a rule admin, an ops bearer token, and the cookieless Umami site without rebuilding. --- .env.example | 1 + app/layout.tsx | 46 ++++++++++++++++-------------- docs/guides/ops-backend-deploy.md | 21 ++++++++++++-- docs/guides/ops-runbook.md | 33 ++++++++++++++------- lib/umami.ts | 12 ++++++-- next.config.mjs | 26 ++++++++++------- scripts/staging-smoke.sh | 26 +++++++++++++++++ tests/unit/securityHeaders.test.ts | 3 ++ tests/unit/umami.test.ts | 13 +++++++++ 9 files changed, 132 insertions(+), 49 deletions(-) diff --git a/.env.example b/.env.example index 2a11349..da3552d 100644 --- a/.env.example +++ b/.env.example @@ -61,6 +61,7 @@ NEXT_PUBLIC_ENABLE_BACKEND_SYNC= # Optional Umami (self-hosted beside the app). Unset: no tracker script. # Cookie-free / no-cookies is an Umami server setting. +# Read at request time on Cloudron, so `cloudron env set` does not need a rebuild. # NEXT_PUBLIC_UMAMI_SRC=https://analytics.example.com/script.js # NEXT_PUBLIC_UMAMI_WEBSITE_ID= diff --git a/app/layout.tsx b/app/layout.tsx index 439c3bf..3d9c1a9 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,7 +1,8 @@ import { Inter, Bricolage_Grotesque } from "next/font/google"; import type { Metadata, Viewport } from "next"; -import type { ReactNode } from "react"; +import { Suspense, type ReactNode } from "react"; import { headers } from "next/headers"; +import { connection } from "next/server"; import Script from "next/script"; import messages from "../messages/en/index"; import { ASSETS, getAssetPath } from "../lib/assetUtils"; @@ -125,9 +126,22 @@ export async function generateMetadata(): Promise { }; } -export default function RootLayout({ children }: { children: ReactNode }) { +async function UmamiScript() { + await connection(); const umami = umamiTracker(); + if (!umami) return null; + return ( +