Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9433ec4285 |
@@ -84,23 +84,13 @@ jobs:
|
|||||||
run: pnpm test
|
run: pnpm test
|
||||||
|
|
||||||
# Sentry toont bij elke fout uit welke commit de build komt
|
# Sentry toont bij elke fout uit welke commit de build komt
|
||||||
# Dit artefact (dist) is ook wat naar productie gaat: met de gecommitte
|
# Dit artefact (dist) is ook wat naar productie gaat: bewust zonder
|
||||||
# pakketlijst (snapshot), zonder testadres en met dicht formulier. De
|
# OFFERINGS_URL, dus met de gecommitte pakketlijst. De testbuild met de
|
||||||
# CMS-host schrijft de actuele gegevens bij elk verzoek in de HTML.
|
# pakketten uit het CMS is job build-test.
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: pnpm build
|
||||||
# Zonder deze waarden meet de site stilletjes niets: liever een rode build
|
|
||||||
for name in VITE_SENTRY_DSN VITE_UMAMI_SCRIPT_URL VITE_UMAMI_WEBSITE_ID; do
|
|
||||||
[ -n "${!name}" ] || { echo "$name ontbreekt: stel de Gitea-variabele PROD_${name#VITE_} in"; exit 1; }
|
|
||||||
done
|
|
||||||
pnpm build
|
|
||||||
env:
|
env:
|
||||||
VITE_RELEASE: ${{ github.sha }}
|
VITE_RELEASE: ${{ github.sha }}
|
||||||
# Monitoring van de productiesite (src/monitoring/config.ts)
|
|
||||||
VITE_APP_ENV: production
|
|
||||||
VITE_SENTRY_DSN: ${{ vars.PROD_SENTRY_DSN }}
|
|
||||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.PROD_UMAMI_SCRIPT_URL }}
|
|
||||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.PROD_UMAMI_WEBSITE_ID }}
|
|
||||||
|
|
||||||
- name: Audit (productiepakketten, blokkerend)
|
- name: Audit (productiepakketten, blokkerend)
|
||||||
run: pnpm audit:deps
|
run: pnpm audit:deps
|
||||||
@@ -115,10 +105,10 @@ jobs:
|
|||||||
path: web/dist/client/
|
path: web/dist/client/
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
|
|
||||||
# De build voor de testsite: zelfde code als dist, maar met het eigen adres
|
# De build voor de testsite: zelfde code als dist, maar met de pakketten uit
|
||||||
# van de testsite en het formulier open. De pakketten komen niet meer uit
|
# het CMS van de testomgeving (OFFERINGS_URL uit de repo-variabele
|
||||||
# het CMS bij de build: de CMS-host injecteert ze bij elk verzoek.
|
# ASF_OFFERINGS_URL_TEST). Productie krijgt dit artefact nooit: die blijft op
|
||||||
# Productie krijgt dit artefact nooit.
|
# dist met de gecommitte lijst tot er een productie-CMS is.
|
||||||
build-test:
|
build-test:
|
||||||
needs: check
|
needs: check
|
||||||
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')
|
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')
|
||||||
@@ -147,20 +137,11 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
|
|
||||||
- name: Build (testomgeving)
|
- name: Build (testomgeving, pakketten uit het CMS)
|
||||||
run: |
|
run: pnpm build
|
||||||
# Zonder deze waarden meet de site stilletjes niets: liever een rode build
|
|
||||||
for name in VITE_SENTRY_DSN VITE_UMAMI_SCRIPT_URL VITE_UMAMI_WEBSITE_ID; do
|
|
||||||
[ -n "${!name}" ] || { echo "$name ontbreekt: stel de Gitea-variabele TEST_${name#VITE_} in"; exit 1; }
|
|
||||||
done
|
|
||||||
pnpm build
|
|
||||||
env:
|
env:
|
||||||
VITE_RELEASE: ${{ github.sha }}
|
VITE_RELEASE: ${{ github.sha }}
|
||||||
# Monitoring van de testsite (src/monitoring/config.ts)
|
OFFERINGS_URL: ${{ vars.ASF_OFFERINGS_URL_TEST }}
|
||||||
VITE_APP_ENV: test
|
|
||||||
VITE_SENTRY_DSN: ${{ vars.TEST_SENTRY_DSN }}
|
|
||||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.TEST_UMAMI_SCRIPT_URL }}
|
|
||||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.TEST_UMAMI_WEBSITE_ID }}
|
|
||||||
# De testsite staat op zichzelf: canonical, og:url, og:image,
|
# De testsite staat op zichzelf: canonical, og:url, og:image,
|
||||||
# JSON-LD en sitemap wijzen naar het eigen adres, zodat een gedeelde
|
# JSON-LD en sitemap wijzen naar het eigen adres, zodat een gedeelde
|
||||||
# link (WhatsApp, Discord) ook zijn eigen plaatje toont. Alleen in
|
# link (WhatsApp, Discord) ook zijn eigen plaatje toont. Alleen in
|
||||||
@@ -216,10 +197,10 @@ jobs:
|
|||||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||||
DEPLOY_PATH: ${{ vars.TEST_DEPLOY_PATH }}
|
DEPLOY_PATH: ${{ vars.DEPLOY_PATH_TEST }}
|
||||||
run: |
|
run: |
|
||||||
case "$DEPLOY_PATH" in
|
case "$DEPLOY_PATH" in
|
||||||
''|'/'|*' '*) echo "TEST_DEPLOY_PATH ontbreekt of is ongeldig: '$DEPLOY_PATH'"; exit 1 ;;
|
''|'/'|*' '*) echo "DEPLOY_PATH_TEST ontbreekt of is ongeldig: '$DEPLOY_PATH'"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
sudo apt-get update && sudo apt-get install -y sshpass
|
sudo apt-get update && sudo apt-get install -y sshpass
|
||||||
SSH="sshpass -e ssh -p $SSH_PORT -o StrictHostKeyChecking=accept-new $SSH_USER@$SSH_HOST"
|
SSH="sshpass -e ssh -p $SSH_PORT -o StrictHostKeyChecking=accept-new $SSH_USER@$SSH_HOST"
|
||||||
@@ -242,17 +223,18 @@ jobs:
|
|||||||
# dus staan voor de deploy (zie pi-install-instructions.md).
|
# dus staan voor de deploy (zie pi-install-instructions.md).
|
||||||
- name: Controle na deploy
|
- name: Controle na deploy
|
||||||
env:
|
env:
|
||||||
HEALTH_URL: ${{ vars.TEST_HEALTH_URL }}
|
HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_TEST }}
|
||||||
# De CSP komt uit dezelfde bron als de build (Umami en Sentry)
|
# 'true' zodra test.andreaslop.nl door de CMS-host (Api.AndreaSlopFotografie)
|
||||||
VITE_APP_ENV: test
|
# wordt bediend in plaats van nginx: dan controleert het script ook de
|
||||||
VITE_SENTRY_DSN: ${{ vars.TEST_SENTRY_DSN }}
|
# exacte CSP en de CMS-routes. Zet hem om samen met de proxy-route.
|
||||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.TEST_UMAMI_SCRIPT_URL }}
|
SERVED_BY_CMS: ${{ vars.ASF_TEST_SERVED_BY_CMS }}
|
||||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.TEST_UMAMI_WEBSITE_ID }}
|
|
||||||
run: |
|
run: |
|
||||||
if [ -z "$HEALTH_URL" ]; then echo "Geen TEST_HEALTH_URL ingesteld; overgeslagen"; exit 0; fi
|
if [ -z "$HEALTH_URL" ]; then echo "Geen HEALTH_CHECK_URL_TEST ingesteld; overgeslagen"; exit 0; fi
|
||||||
# test.andreaslop.nl wordt door de CMS-host bediend: het script
|
if [ "$SERVED_BY_CMS" = "true" ]; then
|
||||||
# controleert ook de exacte CSP en de CMS-routes
|
EXPECTED_CSP="$(node config/printCsp.ts)" bash deploy/verify-deployment.sh "$HEALTH_URL" dist --test --cms
|
||||||
EXPECTED_CSP="$(node config/printCsp.ts)" bash deploy/verify-deployment.sh "$HEALTH_URL" dist --test --cms
|
else
|
||||||
|
bash deploy/verify-deployment.sh "$HEALTH_URL" dist --test
|
||||||
|
fi
|
||||||
echo "Test bereikbaar en gelijk aan de build"
|
echo "Test bereikbaar en gelijk aan de build"
|
||||||
|
|
||||||
# Lighthouse tegen de gebouwde site (mobiel en desktop)
|
# Lighthouse tegen de gebouwde site (mobiel en desktop)
|
||||||
@@ -368,10 +350,10 @@ jobs:
|
|||||||
# Deze job kan pas draaien als er een webhost is.
|
# Deze job kan pas draaien als er een webhost is.
|
||||||
- name: Upload naar productie (FTPS)
|
- name: Upload naar productie (FTPS)
|
||||||
env:
|
env:
|
||||||
FTP_HOST: ${{ secrets.PROD_HOST_ADDRESS }}
|
FTP_HOST: ${{ secrets.FTP_HOST }}
|
||||||
FTP_USER: ${{ secrets.PROD_HOST_USERNAME }}
|
FTP_USER: ${{ secrets.FTP_USERNAME }}
|
||||||
LFTP_PASSWORD: ${{ secrets.PROD_HOST_PASSWORD }}
|
LFTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
|
||||||
FTP_DIR: ${{ vars.PROD_DEPLOY_PATH || 'wwwroot' }}
|
FTP_DIR: ${{ vars.FTP_REMOTE_DIR || 'wwwroot' }}
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update && sudo apt-get install -y lftp
|
sudo apt-get update && sudo apt-get install -y lftp
|
||||||
bash deploy/upload-production.sh dist "$FTP_DIR"
|
bash deploy/upload-production.sh dist "$FTP_DIR"
|
||||||
@@ -379,8 +361,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Controle na deploy
|
- name: Controle na deploy
|
||||||
env:
|
env:
|
||||||
HEALTH_URL: ${{ vars.PROD_HEALTH_URL }}
|
HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }}
|
||||||
run: |
|
run: |
|
||||||
if [ -z "$HEALTH_URL" ]; then echo "Geen PROD_HEALTH_URL ingesteld; overgeslagen"; exit 0; fi
|
if [ -z "$HEALTH_URL" ]; then echo "Geen HEALTH_CHECK_URL_PRODUCTION ingesteld; overgeslagen"; exit 0; fi
|
||||||
bash deploy/verify-deployment.sh "$HEALTH_URL" dist
|
bash deploy/verify-deployment.sh "$HEALTH_URL" dist
|
||||||
echo "Productie bereikbaar en gelijk aan de build"
|
echo "Productie bereikbaar en gelijk aan de build"
|
||||||
|
|||||||
@@ -59,11 +59,12 @@ Decision (Bryan, 2026-11-15): the hosting package has one entry per website. The
|
|||||||
|
|
||||||
## Environment and variables
|
## Environment and variables
|
||||||
|
|
||||||
| Name | Where | Meaning |
|
| Name | Where | Meaning |
|
||||||
| --------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `OFFERINGS_URL` | build env | Site address that serves the API (for example `https://test.andreaslop.nl`). Unset gives the snapshot. |
|
| `OFFERINGS_URL` | build env | Site address that serves the API (for example `https://test.andreaslop.nl`). Unset gives the snapshot. |
|
||||||
| `API_PROXY_TARGET` | dev env | Forwards `/api` in `pnpm dev` to a CMS host. |
|
| `ASF_OFFERINGS_URL_TEST` | Gitea repo variable | Value of `OFFERINGS_URL` for the test build. Set by SLS, not by feature sessions. |
|
||||||
| `VITE_SITE_URL` | build env | Address the site presents itself under (canonical, og:*, JSON-LD, sitemap). Only the test build sets it (`https://test.andreaslop.nl`); unset gives `https://andreaslop.nl`. |
|
| `API_PROXY_TARGET` | dev env | Forwards `/api` in `pnpm dev` to a CMS host. |
|
||||||
| `VITE_CONTACT_FORM_ENABLED` | build env | Opens the contact form when exactly `true`. Only the test build sets it; unset keeps the form closed (production). Opening it in production needs Bryan's explicit go, after the captcha decision ([go-live-checklist.md](go-live-checklist.md)). |
|
| `VITE_SITE_URL` | build env | Address the site presents itself under (canonical, og:*, JSON-LD, sitemap). Only the test build sets it (`https://test.andreaslop.nl`); unset gives `https://andreaslop.nl`. |
|
||||||
|
| `VITE_CONTACT_FORM_ENABLED` | build env | Opens the contact form when exactly `true`. Only the test build sets it; unset keeps the form closed (production). Opening it in production needs Bryan's explicit go, after the captcha decision ([go-live-checklist.md](go-live-checklist.md)). |
|
||||||
|
|
||||||
No build sets `OFFERINGS_URL` any more (since the host injection, 2026-11-18): the CMS host writes the current data into the HTML. The variable stays supported for a local build against a CMS. The production artifact never carries the prices of the test CMS.
|
The production artifact is built without `OFFERINGS_URL` on purpose: production must never carry the prices of the test CMS.
|
||||||
|
|||||||
+3
-22
@@ -20,8 +20,8 @@ Dispatch from the CLI (the token comes from your git credentials, never print it
|
|||||||
|
|
||||||
## Jobs
|
## Jobs
|
||||||
|
|
||||||
1. `check`: lint, format, unit/property/axe tests (coverage threshold 100% on `src/lib/**`), build (with the committed package snapshot), audit. Uploads artifact `dist` (this is what production gets).
|
1. `check`: lint, format, unit/property/axe tests (coverage threshold 100% on `src/lib/**`), build **without** `OFFERINGS_URL` (so with the committed snapshot), audit. Uploads artifact `dist` (this is what production gets).
|
||||||
2. `build-test`: builds again with `VITE_CONTACT_FORM_ENABLED=true` and `VITE_SITE_URL=https://test.andreaslop.nl` (see "Own address of the test site") and uploads `dist-test`.
|
2. `build-test`: builds again with `OFFERINGS_URL=${{ vars.ASF_OFFERINGS_URL_TEST }}` (packages and banners from the test CMS) and `VITE_SITE_URL=https://test.andreaslop.nl` (see "Own address of the test site") and uploads `dist-test`.
|
||||||
3. `deploy-test`: needs `check` and `build-test`, downloads `dist-test`, uploads to the ASF test host and runs the deployment check (served by the CMS host, admin files, POST status).
|
3. `deploy-test`: needs `check` and `build-test`, downloads `dist-test`, uploads to the ASF test host and runs the deployment check (served by the CMS host, admin files, POST status).
|
||||||
4. `lighthouse`: against the built site with the preview stub (`--audit-route --contact-stub`).
|
4. `lighthouse`: against the built site with the preview stub (`--audit-route --contact-stub`).
|
||||||
5. `deploy-production`: manual, from `release/*` only, uses artifact `dist`.
|
5. `deploy-production`: manual, from `release/*` only, uses artifact `dist`.
|
||||||
@@ -52,23 +52,4 @@ The test site stands on its own: in the test build `VITE_SITE_URL` is `https://t
|
|||||||
|
|
||||||
There used to be a nightly test build (`schedule`, 03:15 UTC) that baked the CMS data into the HTML for search engines. It is gone: the CMS host writes the packages, banners and hero into the first HTML of every request (cache 60 s, refreshed at once on a change; NFR-10), so a content change is visible without a rebuild. A rebuild is only needed for code and design. The nightly run also put `master` over ASF-test every night, which would undo a feature branch deployed there.
|
There used to be a nightly test build (`schedule`, 03:15 UTC) that baked the CMS data into the HTML for search engines. It is gone: the CMS host writes the packages, banners and hero into the first HTML of every request (cache 60 s, refreshed at once on a change; NFR-10), so a content change is visible without a rebuild. A rebuild is only needed for code and design. The nightly run also put `master` over ASF-test every night, which would undo a feature branch deployed there.
|
||||||
|
|
||||||
The production site gets the same only when the ASF production site is served by the CMS host (the IIS pipeline, later; see [go-live-checklist.md](go-live-checklist.md)). Until then production shows the committed snapshot. The test build no longer sets `OFFERINGS_URL` (removed 2026-11-18, once the host injection was confirmed on ASF-test); it still sets `VITE_SITE_URL` (own address of the test site) and `VITE_CONTACT_FORM_ENABLED`.
|
The production site gets the same only when the ASF production site is served by the CMS host (the IIS pipeline, later; see [go-live-checklist.md](go-live-checklist.md)). Until then production shows the committed snapshot. The test build still sets `OFFERINGS_URL`; removing that (and `VITE_SITE_URL`) is a separate follow-up once host injection is confirmed end to end.
|
||||||
|
|
||||||
## Names of the repo variables and secrets
|
|
||||||
|
|
||||||
Format `{ENV}_{GROUP}_{NAME}` with `ENV` = `TEST` or `PROD`, no app part (this repo only deploys the ASF site) and no `VITE` (the pipeline maps a value to `VITE_...` in the build). Decision of Bryan, 2026-11-18; the full list is in the SLS repo (`aidlc-docs/_shared/gitea-naamgeving-variabelen.md`). Repo variables and secrets are created by SLS, not by feature sessions.
|
|
||||||
|
|
||||||
| Name | Kind | Used by |
|
|
||||||
| ------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
||||||
| `TEST_DEPLOY_PATH` | variable | `deploy-test`: target folder on the Pi |
|
|
||||||
| `TEST_HEALTH_URL` | variable | `deploy-test`: check after the deploy |
|
|
||||||
| `PROD_DEPLOY_PATH` | variable | `deploy-production`: remote folder (default `wwwroot`) |
|
|
||||||
| `PROD_HEALTH_URL` | variable | `deploy-production`: check after the deploy |
|
|
||||||
| `TEST_SENTRY_DSN`, `TEST_UMAMI_SCRIPT_URL`, `TEST_UMAMI_WEBSITE_ID` | variable | `build-test` and the CSP check in `deploy-test` (as `VITE_SENTRY_DSN`, `VITE_UMAMI_SCRIPT_URL`, `VITE_UMAMI_WEBSITE_ID`, `VITE_APP_ENV=test`) |
|
|
||||||
| `PROD_SENTRY_DSN`, `PROD_UMAMI_SCRIPT_URL`, `PROD_UMAMI_WEBSITE_ID` | variable | `check` (the production artifact; `VITE_APP_ENV=production`) |
|
|
||||||
| `PROD_HOST_ADDRESS`, `PROD_HOST_USERNAME`, `PROD_HOST_PASSWORD` | secrets | `deploy-production`: FTP (plain FTP, no FTPS, at the hosting partner) |
|
|
||||||
| `PI_MAIN_ADDRESS`, `_PORT`, `_USERNAME`, `_PASSWORD` | secrets | `deploy-test`: still the old names; they become `TEST_HOST_*` with an SSH key (SLS arranges the key) |
|
|
||||||
|
|
||||||
Removed: `DEPLOY_PATH_TEST`, `HEALTH_CHECK_URL_TEST`, `HEALTH_CHECK_URL_PRODUCTION`, `FTP_REMOTE_DIR`, `FTP_HOST`, `FTP_USERNAME`, `FTP_PASSWORD` (renamed), `ASF_OFFERINGS_URL_TEST` and `ASF_TEST_SERVED_BY_CMS` (no longer needed). The old names in the repo are removed by SLS after a green run.
|
|
||||||
|
|
||||||
**Monitoring per build.** Sentry and Umami settings are no longer in the code (`src/monitoring/config.ts`): every build gets them for its own environment and measures only on that environment's host (production build on `andreaslop.nl`, test build on `test.andreaslop.nl`; any other host measures nothing). The CSP origins for Umami and Sentry (`config/securityHeaders.ts`) come from the same variables, so a build without them has neither a measurement nor those origins; the build steps fail when a variable is empty. Unit and browser tests use the production values from `config/monitoringTestEnv.ts` (public values, the same as the variables); `pnpm server-config` does too, so the committed generated files carry the production CSP. The CMS host has its own copy of the origins in its environment (CMS repo).
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ What must be true before the CMS-driven parts of the site go to production. Brya
|
|||||||
|
|
||||||
- [ ] Production hosting in place with the CMS host as the one entry of the website: IIS passes ALL requests to the CMS host (not only `/api/v1/*`) and serves no static files itself; the prerendered `dist/` is deployed to the CMS host ([cms-integration.md](cms-integration.md), "Hosting"). The generated IIS config and the production upload script are updated for this. Without it production keeps the committed snapshot and the console shows a 404 per page view for the API.
|
- [ ] Production hosting in place with the CMS host as the one entry of the website: IIS passes ALL requests to the CMS host (not only `/api/v1/*`) and serves no static files itself; the prerendered `dist/` is deployed to the CMS host ([cms-integration.md](cms-integration.md), "Hosting"). The generated IIS config and the production upload script are updated for this. Without it production keeps the committed snapshot and the console shows a 404 per page view for the API.
|
||||||
- [ ] `web/src/content/offerings.snapshot.json` holds the real, current packages (production builds use it).
|
- [ ] `web/src/content/offerings.snapshot.json` holds the real, current packages (production builds use it).
|
||||||
- [ ] The production CMS holds the real packages. The test CMS prices must never end up in the production artifact (no build fetches packages from a CMS any more).
|
- [ ] The production CMS holds the real packages. The test CMS prices must never end up in the production artifact (it is built without `OFFERINGS_URL`).
|
||||||
|
|
||||||
## Hero
|
## Hero
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ The contact form must not go live before the statement does.
|
|||||||
## Other open items
|
## Other open items
|
||||||
|
|
||||||
- ASF production hosting: CMS host behind IIS pass-through (separate feature, see above).
|
- ASF production hosting: CMS host behind IIS pass-through (separate feature, see above).
|
||||||
|
- Privacy statement as JSON (Bryan, 2026-11-17): `web/src/content/privacyContent.ts` may become a JSON file, but not now. Do it in the feature that sets up the production pipeline on IIS, together with the text itself (the `[OPEN:]` points, the captcha paragraph, the final wording). Keep the `PLACEHOLDER_MARK` check (`unresolvedPlaceholders()`), the captcha section (`onlyWithCaptcha`) and their tests. Put this in the plan of that feature.
|
||||||
- Host injection of CMS data into the prerendered pages (plan: `aidlc-docs/features/asf-cms-host-injection/plan.md`, after the current merges).
|
- Host injection of CMS data into the prerendered pages (plan: `aidlc-docs/features/asf-cms-host-injection/plan.md`, after the current merges).
|
||||||
- First ASF administrator and removal of the setup token (CMS).
|
- First ASF administrator and removal of the setup token (CMS).
|
||||||
- Messages created by the Playwright test run in the ASF test CMS are archived by Bryan.
|
- Messages created by the Playwright test run in the ASF test CMS are archived by Bryan.
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
// De monitoringinstellingen die de tests als productiebuild zien. De echte
|
|
||||||
// waarden komen in de pipeline uit de Gitea-variabelen PROD_SENTRY_DSN,
|
|
||||||
// PROD_UMAMI_SCRIPT_URL en PROD_UMAMI_WEBSITE_ID (en TEST_...); deze openbare
|
|
||||||
// waarden zijn er hetzelfde als, zodat de gegenereerde serverconfiguratie en de
|
|
||||||
// CSP in de tests vergelijkbaar blijven. Zie src/monitoring/config.ts.
|
|
||||||
export const monitoringTestEnv = {
|
|
||||||
VITE_APP_ENV: 'production',
|
|
||||||
VITE_SENTRY_DSN:
|
|
||||||
'https://12ec77dcc3216a98b96d3fb3dac13f66@o4511795618185216.ingest.de.sentry.io/4512282287472720',
|
|
||||||
VITE_UMAMI_SCRIPT_URL: 'https://analytics.slpsoftware.nl/script.js',
|
|
||||||
VITE_UMAMI_WEBSITE_ID: '3edbb7d1-4388-4f2d-9cef-11ade88ace96',
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { contentSecurityPolicy, securityHeaders } from './securityHeaders';
|
import { contentSecurityPolicy, securityHeaders } from './securityHeaders';
|
||||||
|
|
||||||
const umami = 'https://analytics.slpsoftware.nl';
|
const umami = 'https://analytics.slpsoftware.nl';
|
||||||
@@ -12,17 +12,7 @@ const captchaFrames = [
|
|||||||
const directive = (csp: string, name: string) =>
|
const directive = (csp: string, name: string) =>
|
||||||
csp.split('; ').find((d) => d.startsWith(name + ' ')) ?? '';
|
csp.split('; ').find((d) => d.startsWith(name + ' ')) ?? '';
|
||||||
|
|
||||||
afterEach(() => vi.unstubAllEnvs());
|
|
||||||
|
|
||||||
describe('securityHeaders', () => {
|
describe('securityHeaders', () => {
|
||||||
it('noemt Umami en Sentry niet zonder monitoringinstellingen in de build', () => {
|
|
||||||
vi.stubEnv('VITE_SENTRY_DSN', '');
|
|
||||||
const csp = contentSecurityPolicy('production');
|
|
||||||
expect(csp).not.toContain(umami);
|
|
||||||
expect(csp).not.toContain(sentry);
|
|
||||||
expect(directive(csp, 'script-src')).toBe("script-src 'self'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('productie-CSP heeft geen onveilige uitzonderingen voor scripts', () => {
|
it('productie-CSP heeft geen onveilige uitzonderingen voor scripts', () => {
|
||||||
const csp = contentSecurityPolicy('production');
|
const csp = contentSecurityPolicy('production');
|
||||||
expect(csp).not.toContain('unsafe-eval');
|
expect(csp).not.toContain('unsafe-eval');
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// HTTP-securityheaders voor de Vite dev- en preview-server. De productieset is
|
// HTTP-securityheaders voor de Vite dev- en preview-server. De productieset is
|
||||||
// ook het voorschrift voor de toekomstige host (zie NFR-SEC-01/02).
|
// ook het voorschrift voor de toekomstige host (zie NFR-SEC-01/02).
|
||||||
|
|
||||||
import { monitoringOrigins } from '../src/monitoring/config.ts';
|
import { sentryIngestOrigin, umamiOrigin } from '../src/monitoring/config.ts';
|
||||||
|
|
||||||
type Mode = 'production' | 'development';
|
type Mode = 'production' | 'development';
|
||||||
|
|
||||||
@@ -21,24 +21,19 @@ export const captchaFrameOrigins = [
|
|||||||
'https://global1.frcapi.com',
|
'https://global1.frcapi.com',
|
||||||
];
|
];
|
||||||
|
|
||||||
// De herkomsten van Umami en Sentry komen uit de build-omgeving (zie
|
const productionCsp: Record<string, string[]> = {
|
||||||
// src/monitoring/config.ts); zonder die instellingen staan ze er niet in.
|
'default-src': ["'self'"],
|
||||||
function productionCsp(): Record<string, string[]> {
|
'script-src': ["'self'", umamiOrigin],
|
||||||
const origins = monitoringOrigins();
|
'style-src': ["'self'", "'unsafe-inline'"],
|
||||||
return {
|
'img-src': ["'self'", 'data:'],
|
||||||
'default-src': ["'self'"],
|
'font-src': ["'self'"],
|
||||||
'script-src': ["'self'", ...origins.umami],
|
'connect-src': ["'self'", umamiOrigin, sentryIngestOrigin],
|
||||||
'style-src': ["'self'", "'unsafe-inline'"],
|
'frame-src': captchaFrameOrigins,
|
||||||
'img-src': ["'self'", 'data:'],
|
'object-src': ["'none'"],
|
||||||
'font-src': ["'self'"],
|
'base-uri': ["'self'"],
|
||||||
'connect-src': ["'self'", ...origins.umami, ...origins.sentry],
|
'form-action': ["'self'"],
|
||||||
'frame-src': captchaFrameOrigins,
|
'frame-ancestors': ["'none'"],
|
||||||
'object-src': ["'none'"],
|
};
|
||||||
'base-uri': ["'self'"],
|
|
||||||
'form-action': ["'self'"],
|
|
||||||
'frame-ancestors': ["'none'"],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alleen wat de Vite dev-server zelf nodig heeft: een inline script voor
|
// Alleen wat de Vite dev-server zelf nodig heeft: een inline script voor
|
||||||
// React Refresh en een websocket voor hot reload.
|
// React Refresh en een websocket voor hot reload.
|
||||||
@@ -48,7 +43,7 @@ const developmentExtras: Record<string, string[]> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function contentSecurityPolicy(mode: Mode): string {
|
export function contentSecurityPolicy(mode: Mode): string {
|
||||||
return Object.entries(productionCsp())
|
return Object.entries(productionCsp)
|
||||||
.map(([directive, sources]) => {
|
.map(([directive, sources]) => {
|
||||||
const extra =
|
const extra =
|
||||||
mode === 'development'
|
mode === 'development'
|
||||||
|
|||||||
@@ -2,15 +2,8 @@
|
|||||||
// Draait direct met Node (type stripping), zonder extra tooling.
|
// Draait direct met Node (type stripping), zonder extra tooling.
|
||||||
import { mkdirSync, writeFileSync } from 'node:fs';
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
||||||
import { dirname } from 'node:path';
|
import { dirname } from 'node:path';
|
||||||
import { monitoringTestEnv } from './monitoringTestEnv.ts';
|
|
||||||
import { serverConfigFiles } from './serverConfig.ts';
|
import { serverConfigFiles } from './serverConfig.ts';
|
||||||
|
|
||||||
// The committed files carry the CSP of the production build; the origins of
|
|
||||||
// Umami and Sentry come from the environment (src/monitoring/config.ts)
|
|
||||||
for (const [name, value] of Object.entries(monitoringTestEnv)) {
|
|
||||||
process.env[name] ??= value;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [path, generate] of Object.entries(serverConfigFiles)) {
|
for (const [path, generate] of Object.entries(serverConfigFiles)) {
|
||||||
mkdirSync(dirname(path), { recursive: true });
|
mkdirSync(dirname(path), { recursive: true });
|
||||||
writeFileSync(path, generate());
|
writeFileSync(path, generate());
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
# headers staan met de exacte waarde op elk antwoord (pagina, asset,
|
# headers staan met de exacte waarde op elk antwoord (pagina, asset,
|
||||||
# 301, 404, robots.txt), cachebeleid, alleen gzip (nooit br), een
|
# 301, 404, robots.txt), cachebeleid, alleen gzip (nooit br), een
|
||||||
# procentgecodeerd pad blijft gecodeerd, en /admin, /health en
|
# procentgecodeerd pad blijft gecodeerd, en /admin, /health en
|
||||||
# /api/v1/System/capabilities (met Offerings en Hero) antwoorden.
|
# /api/v1/System/capabilities (zonder Offerings) antwoorden.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
|
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
|
||||||
@@ -272,7 +272,7 @@ if [ "$cms_mode" -eq 1 ]; then
|
|||||||
fail "POST /: status $status, verwacht 405"
|
fail "POST /: status $status, verwacht 405"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# De CMS-routes: health, admin, API (met Offerings en Hero), onbekend API-pad
|
# De CMS-routes: health, admin, API (zonder Offerings), onbekend API-pad
|
||||||
fetch /health
|
fetch /health
|
||||||
if [ "$status" != "200" ]; then fail "/health: status $status, verwacht 200"; fi
|
if [ "$status" != "200" ]; then fail "/health: status $status, verwacht 200"; fi
|
||||||
|
|
||||||
@@ -301,13 +301,8 @@ if [ "$cms_mode" -eq 1 ]; then
|
|||||||
fetch /api/v1/System/capabilities
|
fetch /api/v1/System/capabilities
|
||||||
if [ "$status" != "200" ]; then
|
if [ "$status" != "200" ]; then
|
||||||
fail "/api/v1/System/capabilities: status $status, verwacht 200"
|
fail "/api/v1/System/capabilities: status $status, verwacht 200"
|
||||||
else
|
elif grep -qi 'offerings' "$work/body"; then
|
||||||
# De site haalt pakketten, banners en de hero uit deze modules
|
fail "/api/v1/System/capabilities noemt Offerings; die module hoort voor ASF uit te staan"
|
||||||
for module in Offerings Hero; do
|
|
||||||
if ! grep -qi "\"$module\"" "$work/body"; then
|
|
||||||
fail "/api/v1/System/capabilities noemt $module niet; de site heeft die module nodig"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Een onbekend API-pad is een API-404, nooit de website
|
# Een onbekend API-pad is een API-404, nooit de website
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { render } from '@testing-library/react';
|
import { render } from '@testing-library/react';
|
||||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
import { afterEach, describe, expect, it } from 'vitest';
|
||||||
import UmamiAnalytics from './UmamiAnalytics';
|
import UmamiAnalytics from './UmamiAnalytics';
|
||||||
|
|
||||||
const umamiScripts = () =>
|
const umamiScripts = () =>
|
||||||
@@ -8,7 +8,6 @@ const umamiScripts = () =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.unstubAllEnvs();
|
|
||||||
umamiScripts().forEach((script) => script.remove());
|
umamiScripts().forEach((script) => script.remove());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -19,28 +18,18 @@ describe('UmamiAnalytics', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['production', 'andreaslop.nl', '3edbb7d1-4388-4f2d-9cef-11ade88ace96'],
|
['andreaslop.nl', '3edbb7d1-4388-4f2d-9cef-11ade88ace96'],
|
||||||
['test', 'test.andreaslop.nl', 'test-website'],
|
['test.andreaslop.nl', '7fb301ab-6ecc-4aea-beee-71bcb6009bfe'],
|
||||||
])(
|
])('telt op %s met de juiste website', (hostname, websiteId) => {
|
||||||
'telt in de %s-build op %s met de juiste website',
|
render(<UmamiAnalytics hostname={hostname} />);
|
||||||
(environment, hostname, websiteId) => {
|
|
||||||
vi.stubEnv('VITE_APP_ENV', environment);
|
|
||||||
vi.stubEnv('VITE_UMAMI_WEBSITE_ID', websiteId);
|
|
||||||
render(<UmamiAnalytics hostname={hostname} />);
|
|
||||||
|
|
||||||
const [script] = umamiScripts();
|
const [script] = umamiScripts();
|
||||||
expect(script.defer).toBe(true);
|
expect(script.defer).toBe(true);
|
||||||
expect(script.dataset).toMatchObject({
|
expect(script.dataset).toMatchObject({
|
||||||
websiteId,
|
websiteId,
|
||||||
domains: hostname,
|
domains: hostname,
|
||||||
doNotTrack: 'true',
|
doNotTrack: 'true',
|
||||||
});
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
it('voegt geen script toe op de host van de andere omgeving', () => {
|
|
||||||
render(<UmamiAnalytics hostname="test.andreaslop.nl" />);
|
|
||||||
expect(umamiScripts()).toHaveLength(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('voegt het script maar één keer toe', () => {
|
it('voegt het script maar één keer toe', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { monitoringFor } from '@/monitoring/config';
|
import { monitoringFor, umamiOrigin } from '@/monitoring/config';
|
||||||
|
|
||||||
const SCRIPT_ELEMENT_ID = 'umami-analytics-script';
|
const SCRIPT_ELEMENT_ID = 'umami-analytics-script';
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export default function UmamiAnalytics({ hostname }: { hostname?: string }) {
|
|||||||
|
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.id = SCRIPT_ELEMENT_ID;
|
script.id = SCRIPT_ELEMENT_ID;
|
||||||
script.src = monitoring.umamiScriptUrl;
|
script.src = `${umamiOrigin}/script.js`;
|
||||||
script.defer = true;
|
script.defer = true;
|
||||||
script.dataset.websiteId = monitoring.umamiWebsiteId;
|
script.dataset.websiteId = monitoring.umamiWebsiteId;
|
||||||
script.dataset.domains = host;
|
script.dataset.domains = host;
|
||||||
|
|||||||
@@ -1,22 +1,11 @@
|
|||||||
import fc from 'fast-check';
|
import fc from 'fast-check';
|
||||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import {
|
import {
|
||||||
monitoredHostnames,
|
monitoredHostnames,
|
||||||
monitoringConfig,
|
|
||||||
monitoringFor,
|
monitoringFor,
|
||||||
monitoringOrigins,
|
sentryIngestOrigin,
|
||||||
} from './config';
|
} from './config';
|
||||||
|
|
||||||
const dsn = 'https://key@o1.ingest.de.sentry.io/2';
|
|
||||||
const script = 'https://analytics.example.nl/script.js';
|
|
||||||
const raw = (extra: Record<string, unknown> = {}) => ({
|
|
||||||
environment: 'production',
|
|
||||||
sentryDsn: dsn,
|
|
||||||
umamiScriptUrl: script,
|
|
||||||
umamiWebsiteId: 'site-1',
|
|
||||||
...extra,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Alles wat geen test- of productiehost is
|
// Alles wat geen test- of productiehost is
|
||||||
const otherHostname = fc
|
const otherHostname = fc
|
||||||
.oneof(
|
.oneof(
|
||||||
@@ -36,89 +25,32 @@ const otherHostname = fc
|
|||||||
)
|
)
|
||||||
.filter((host) => !monitoredHostnames.includes(host));
|
.filter((host) => !monitoredHostnames.includes(host));
|
||||||
|
|
||||||
afterEach(() => vi.unstubAllEnvs());
|
describe('monitoringFor', () => {
|
||||||
|
it('productiehost meet als production met de productiewebsite', () => {
|
||||||
describe('monitoringConfig', () => {
|
expect(monitoringFor('andreaslop.nl')).toEqual({
|
||||||
it('leest de waarden uit de omgeving van de build', () => {
|
|
||||||
// De testomgeving (vite.config.ts) is de productiebuild
|
|
||||||
expect(monitoringConfig()).toMatchObject({
|
|
||||||
environment: 'production',
|
environment: 'production',
|
||||||
umamiWebsiteId: '3edbb7d1-4388-4f2d-9cef-11ade88ace96',
|
umamiWebsiteId: '3edbb7d1-4388-4f2d-9cef-11ade88ace96',
|
||||||
});
|
});
|
||||||
vi.stubEnv('VITE_APP_ENV', 'test');
|
});
|
||||||
vi.stubEnv('VITE_UMAMI_WEBSITE_ID', ' abc ');
|
|
||||||
expect(monitoringConfig()).toMatchObject({
|
it('testhost meet als test met de testwebsite', () => {
|
||||||
|
expect(monitoringFor('test.andreaslop.nl')).toEqual({
|
||||||
environment: 'test',
|
environment: 'test',
|
||||||
umamiWebsiteId: 'abc',
|
umamiWebsiteId: '7fb301ab-6ecc-4aea-beee-71bcb6009bfe',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('geeft null als er iets ontbreekt of ongeldig is', () => {
|
|
||||||
expect(monitoringConfig(raw())).not.toBeNull();
|
|
||||||
for (const bad of [
|
|
||||||
{ environment: 'staging' },
|
|
||||||
{ environment: undefined },
|
|
||||||
{ sentryDsn: undefined },
|
|
||||||
{ sentryDsn: 'http://key@host/1' },
|
|
||||||
{ sentryDsn: 'geen url' },
|
|
||||||
{ umamiScriptUrl: '' },
|
|
||||||
{ umamiScriptUrl: 'http://analytics.example.nl/script.js' },
|
|
||||||
{ umamiWebsiteId: ' ' },
|
|
||||||
{ umamiWebsiteId: 5 },
|
|
||||||
]) {
|
|
||||||
expect(monitoringConfig(raw(bad))).toBeNull();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('monitoringFor', () => {
|
|
||||||
it('productiebuild meet alleen op de productiehost', () => {
|
|
||||||
const config = monitoringConfig(raw());
|
|
||||||
expect(monitoringFor('andreaslop.nl', config)).toEqual({
|
|
||||||
environment: 'production',
|
|
||||||
sentryDsn: dsn,
|
|
||||||
umamiScriptUrl: script,
|
|
||||||
umamiWebsiteId: 'site-1',
|
|
||||||
});
|
|
||||||
expect(monitoringFor('test.andreaslop.nl', config)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('testbuild meet alleen op de testhost', () => {
|
|
||||||
const config = monitoringConfig(raw({ environment: 'test' }));
|
|
||||||
expect(monitoringFor('test.andreaslop.nl', config)?.environment).toBe(
|
|
||||||
'test',
|
|
||||||
);
|
|
||||||
expect(monitoringFor('andreaslop.nl', config)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('meet niets zonder instellingen', () => {
|
|
||||||
expect(monitoringFor('andreaslop.nl', null)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('elke andere host meet niets (M1)', () => {
|
it('elke andere host meet niets (M1)', () => {
|
||||||
fc.assert(
|
fc.assert(
|
||||||
fc.property(otherHostname, (host) => {
|
fc.property(otherHostname, (host) => {
|
||||||
expect(monitoringFor(host)).toBeNull();
|
expect(monitoringFor(host)).toBeNull();
|
||||||
expect(
|
|
||||||
monitoringFor(
|
|
||||||
host,
|
|
||||||
monitoringConfig(raw({ environment: 'test' })),
|
|
||||||
),
|
|
||||||
).toBeNull();
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('monitoringOrigins', () => {
|
it('Sentry-ingest is de EU-host uit de DSN, zonder sleutel', () => {
|
||||||
it('zijn de herkomst van het Umami-script en van de Sentry-ingest, zonder sleutel', () => {
|
expect(sentryIngestOrigin).toBe(
|
||||||
expect(monitoringOrigins(monitoringConfig(raw()))).toEqual({
|
'https://o4511795618185216.ingest.de.sentry.io',
|
||||||
umami: ['https://analytics.example.nl'],
|
);
|
||||||
sentry: ['https://o1.ingest.de.sentry.io'],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('zijn leeg zonder instellingen', () => {
|
|
||||||
expect(monitoringOrigins(null)).toEqual({ umami: [], sentry: [] });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,96 +1,43 @@
|
|||||||
// Instellingen voor Sentry en Umami (monitoring-plan M1/M2). De waarden zijn
|
// Instellingen voor Sentry en Umami (monitoring-plan M1/M2). Deze waarden zijn
|
||||||
// openbaar (ze staan in de browser van elke bezoeker) maar komen niet meer uit
|
// openbaar: ze staan hoe dan ook in de browser van elke bezoeker.
|
||||||
// de code: de pipeline geeft ze per omgeving mee aan de build, uit de Gitea-
|
|
||||||
// variabelen {TEST|PROD}_SENTRY_DSN, _UMAMI_SCRIPT_URL en _UMAMI_WEBSITE_ID,
|
|
||||||
// als VITE_SENTRY_DSN, VITE_UMAMI_SCRIPT_URL, VITE_UMAMI_WEBSITE_ID en
|
|
||||||
// VITE_APP_ENV ('test' of 'production'). Eén build hoort dus bij één omgeving.
|
|
||||||
// Geen imports uit Vite: config/securityHeaders.ts leest dit bestand ook in Node.
|
// Geen imports uit Vite: config/securityHeaders.ts leest dit bestand ook in Node.
|
||||||
|
|
||||||
export type MonitoringEnvironment = 'test' | 'production';
|
export type MonitoringEnvironment = 'test' | 'production';
|
||||||
|
|
||||||
export interface MonitoringConfig {
|
export interface Monitoring {
|
||||||
environment: MonitoringEnvironment;
|
environment: MonitoringEnvironment;
|
||||||
sentryDsn: string;
|
|
||||||
umamiScriptUrl: string;
|
|
||||||
umamiWebsiteId: string;
|
umamiWebsiteId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Monitoring = MonitoringConfig;
|
export const sentryDsn =
|
||||||
|
'https://12ec77dcc3216a98b96d3fb3dac13f66@o4511795618185216.ingest.de.sentry.io/4512282287472720';
|
||||||
|
|
||||||
// De host waarop de build van een omgeving meet
|
// Waar de browser fouten naartoe stuurt; nodig voor connect-src in de CSP
|
||||||
const hostnameByEnvironment: Record<MonitoringEnvironment, string> = {
|
export const sentryIngestOrigin = new URL(sentryDsn).origin;
|
||||||
production: 'andreaslop.nl',
|
|
||||||
test: 'test.andreaslop.nl',
|
|
||||||
};
|
|
||||||
|
|
||||||
// In de Vite-build staan de waarden in import.meta.env (statisch vervangen,
|
export const umamiOrigin = 'https://analytics.slpsoftware.nl';
|
||||||
// daarom elke naam los); de buildscripts onder Node lezen process.env.
|
|
||||||
const fromProcess = (name: string): unknown =>
|
|
||||||
typeof process === 'undefined' ? undefined : process.env[name];
|
|
||||||
|
|
||||||
function rawSettings(): Record<keyof MonitoringConfig, unknown> {
|
// Eén build voor beide omgevingen: de hostname bepaalt de omgeving
|
||||||
const env = import.meta.env;
|
const monitoringByHostname = new Map<string, Monitoring>([
|
||||||
return {
|
[
|
||||||
environment: env?.VITE_APP_ENV ?? fromProcess('VITE_APP_ENV'),
|
'andreaslop.nl',
|
||||||
sentryDsn: env?.VITE_SENTRY_DSN ?? fromProcess('VITE_SENTRY_DSN'),
|
{
|
||||||
umamiScriptUrl:
|
environment: 'production',
|
||||||
env?.VITE_UMAMI_SCRIPT_URL ?? fromProcess('VITE_UMAMI_SCRIPT_URL'),
|
umamiWebsiteId: '3edbb7d1-4388-4f2d-9cef-11ade88ace96',
|
||||||
umamiWebsiteId:
|
},
|
||||||
env?.VITE_UMAMI_WEBSITE_ID ?? fromProcess('VITE_UMAMI_WEBSITE_ID'),
|
],
|
||||||
};
|
[
|
||||||
|
'test.andreaslop.nl',
|
||||||
|
{
|
||||||
|
environment: 'test',
|
||||||
|
umamiWebsiteId: '7fb301ab-6ecc-4aea-beee-71bcb6009bfe',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Onbekende host (localhost, Lighthouse CI, previews): niets meten (M1)
|
||||||
|
export function monitoringFor(hostname: string): Monitoring | null {
|
||||||
|
return monitoringByHostname.get(hostname) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isHttps = (value: string): boolean => {
|
export const monitoredHostnames = [...monitoringByHostname.keys()];
|
||||||
try {
|
|
||||||
return new URL(value).protocol === 'https:';
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// De instellingen van deze build, of null als er iets ontbreekt of ongeldig is
|
|
||||||
// (dan meet de site niets: liever geen meting dan een kapotte)
|
|
||||||
export function monitoringConfig(
|
|
||||||
raw: Record<keyof MonitoringConfig, unknown> = rawSettings(),
|
|
||||||
): MonitoringConfig | null {
|
|
||||||
const { environment, sentryDsn, umamiScriptUrl, umamiWebsiteId } = raw;
|
|
||||||
if (environment !== 'test' && environment !== 'production') return null;
|
|
||||||
const text = (value: unknown) =>
|
|
||||||
typeof value === 'string' ? value.trim() : '';
|
|
||||||
const dsn = text(sentryDsn);
|
|
||||||
const script = text(umamiScriptUrl);
|
|
||||||
const website = text(umamiWebsiteId);
|
|
||||||
if (!isHttps(dsn) || !isHttps(script) || website === '') return null;
|
|
||||||
return {
|
|
||||||
environment,
|
|
||||||
sentryDsn: dsn,
|
|
||||||
umamiScriptUrl: script,
|
|
||||||
umamiWebsiteId: website,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Onbekende host (localhost, Lighthouse CI, previews, de andere omgeving):
|
|
||||||
// niets meten (M1)
|
|
||||||
export function monitoringFor(
|
|
||||||
hostname: string,
|
|
||||||
config: MonitoringConfig | null = monitoringConfig(),
|
|
||||||
): Monitoring | null {
|
|
||||||
if (!config || hostname !== hostnameByEnvironment[config.environment]) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return { ...config };
|
|
||||||
}
|
|
||||||
|
|
||||||
// De herkomsten voor de CSP: Umami voor script-src en connect-src, de Sentry-
|
|
||||||
// ingest voor connect-src. Leeg zonder meting.
|
|
||||||
export function monitoringOrigins(
|
|
||||||
config: MonitoringConfig | null = monitoringConfig(),
|
|
||||||
): { umami: string[]; sentry: string[] } {
|
|
||||||
if (!config) return { umami: [], sentry: [] };
|
|
||||||
return {
|
|
||||||
umami: [new URL(config.umamiScriptUrl).origin],
|
|
||||||
sentry: [new URL(config.sentryDsn).origin],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const monitoredHostnames = Object.values(hostnameByEnvironment);
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ async function freshSentry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.unstubAllEnvs();
|
|
||||||
init.mockReset();
|
init.mockReset();
|
||||||
captureException.mockReset();
|
captureException.mockReset();
|
||||||
});
|
});
|
||||||
@@ -28,7 +27,6 @@ describe('Sentry', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('start op test met omgeving test en zonder persoonsgegevens', async () => {
|
it('start op test met omgeving test en zonder persoonsgegevens', async () => {
|
||||||
vi.stubEnv('VITE_APP_ENV', 'test');
|
|
||||||
const { startSentry } = await freshSentry();
|
const { startSentry } = await freshSentry();
|
||||||
startSentry('test.andreaslop.nl');
|
startSentry('test.andreaslop.nl');
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { monitoringFor } from './config';
|
import { monitoringFor, sentryDsn } from './config';
|
||||||
|
|
||||||
// Sentry laadt pas na het load-event, buiten de hoofdbundel (M4). Fouten van
|
// Sentry laadt pas na het load-event, buiten de hoofdbundel (M4). Fouten van
|
||||||
// daarvoor wachten in een wachtrij en gaan mee zodra Sentry klaar is.
|
// daarvoor wachten in een wachtrij en gaan mee zodra Sentry klaar is.
|
||||||
@@ -33,7 +33,7 @@ export function startSentry(hostname = window.location.hostname): void {
|
|||||||
// Alleen fouten: geen tracing, geen replay, geen persoonsgegevens (M5).
|
// Alleen fouten: geen tracing, geen replay, geen persoonsgegevens (M5).
|
||||||
// Sinds SDK 11 verzamelt Sentry standaard alles; daarom alles expliciet uit.
|
// Sinds SDK 11 verzamelt Sentry standaard alles; daarom alles expliciet uit.
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
dsn: monitoring.sentryDsn,
|
dsn: sentryDsn,
|
||||||
environment: monitoring.environment,
|
environment: monitoring.environment,
|
||||||
release: import.meta.env.VITE_RELEASE,
|
release: import.meta.env.VITE_RELEASE,
|
||||||
dataCollection: {
|
dataCollection: {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { monitoringTestEnv } from './config/monitoringTestEnv.ts';
|
|
||||||
import { configDefaults, defineConfig } from 'vitest/config';
|
import { configDefaults, defineConfig } from 'vitest/config';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
||||||
@@ -81,7 +80,6 @@ export default defineConfig(({ mode }) => ({
|
|||||||
preview: { headers: securityHeaders('production') },
|
preview: { headers: securityHeaders('production') },
|
||||||
test: {
|
test: {
|
||||||
environment: 'jsdom',
|
environment: 'jsdom',
|
||||||
env: monitoringTestEnv,
|
|
||||||
// De CI-runner (Raspberry Pi, arm64) is ±5-8x trager dan een pc; de
|
// De CI-runner (Raspberry Pi, arm64) is ±5-8x trager dan een pc; de
|
||||||
// eerste render met axe duurt daar tot 7 s. 5 s (standaard) is te krap.
|
// eerste render met axe duurt daar tot 7 s. 5 s (standaard) is te krap.
|
||||||
testTimeout: 20_000,
|
testTimeout: 20_000,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
import { monitoringTestEnv } from './config/monitoringTestEnv.ts';
|
|
||||||
|
|
||||||
// Browsertests (BR-TST-05, BR-TST-06) tegen de gebouwde site in dist/client.
|
// Browsertests (BR-TST-05, BR-TST-06) tegen de gebouwde site in dist/client.
|
||||||
// Los van vite.config.ts: de Start-plugin en de jsdom-opzet van de
|
// Los van vite.config.ts: de Start-plugin en de jsdom-opzet van de
|
||||||
@@ -9,7 +8,6 @@ export default defineConfig({
|
|||||||
resolve: { tsconfigPaths: true },
|
resolve: { tsconfigPaths: true },
|
||||||
test: {
|
test: {
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
env: monitoringTestEnv,
|
|
||||||
include: ['e2e/**/*.e2e.ts'],
|
include: ['e2e/**/*.e2e.ts'],
|
||||||
// De CI-runner (Raspberry Pi) is veel trager dan een pc: Chrome starten
|
// De CI-runner (Raspberry Pi) is veel trager dan een pc: Chrome starten
|
||||||
// en een pagina hydrateren kost daar vele seconden. Tests die alle 11
|
// en een pagina hydrateren kost daar vele seconden. Tests die alle 11
|
||||||
|
|||||||
Reference in New Issue
Block a user