diff --git a/CHANGELOG.md b/CHANGELOG.md index a77fce1..46fad67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ Each package and app has its own section and its own tags (`contracts@1.0.0`, `accounts@1.0.0`, …). +## events@3.6.1 - 2026-11-20 + +- **Events 3.6.1 (fix):** uploading a logo or favicon failed with "uploaded, but the site can't + show it yet" behind a proxy with a file-extension rule (FastPanel's static-file handling sent + `/api/uploads/…png` to the frontend). The site now passes `/api/*` and `/uploads/*` that reach + it on to the backend (new `BACKEND_INTERNAL_URL`, added on deploy). +- **crosscode script:** the nginx site it writes uses `location ^~ /api/` and `^~ /uploads/`. + ## accounts@1.6.0 - 2026-11-20 - **Accounts 1.6.0:** a "New sign-in" email (and WhatsApp for a verified number) after every diff --git a/apps/events/CHANGELOG.md b/apps/events/CHANGELOG.md index 464ee12..38fd760 100644 --- a/apps/events/CHANGELOG.md +++ b/apps/events/CHANGELOG.md @@ -5,6 +5,23 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project follows [Semantic Versioning](https://semver.org/). +## [3.6.1] - 2026-11-20 + +### Fixed + +- **Uploading a logo or favicon under Settings → Branding failed on some servers** with "The logo was + uploaded, but the site can't show it yet". The upload worked, but on a server whose proxy has a + rule for file extensions (static-file caching) every `/api/…` path ending in `.png`, `.ico`, + `.pdf`, `.json` and so on went to the site (Next.js), which answered 404. So the check after the + upload failed, as did pictures, certificate PDFs and `/api/v2/openapi.json`. Two changes: + - The site passes `/api/*` and `/uploads/*` that reach it on to the backend + (`next.config.ts` rewrites, `beforeFiles`). New frontend setting `BACKEND_INTERNAL_URL` + (`http://127.0.0.1:`, added to `.env.production` on deploy). Unset, nothing is + passed on, as before. The end-to-end tests' `E2E_API_PROXY` uses the same rewrites. + - The nginx site the installers write (and DEPLOYMENT.md) sends `/api/` and `/uploads/` to the + backend with `location ^~`, so no regex location can take them. Existing servers keep their + nginx file: change it by hand (DEPLOYMENT.md §4). + ## [3.6.0] - 2026-11-20 Works with any Accounts; the people check needs Accounts 1.5.0 (with an older one it's skipped). diff --git a/apps/events/DEPLOYMENT.md b/apps/events/DEPLOYMENT.md index 8c5831d..b74813d 100644 --- a/apps/events/DEPLOYMENT.md +++ b/apps/events/DEPLOYMENT.md @@ -127,13 +127,17 @@ server { access_log /var/log/nginx/hope-events.access.log hope_proxy; # Visitors only reach this through the VPS over HTTPS, so tell the app so. - location ~ ^/(api|uploads|health|docs)(/|$) { - proxy_pass http://127.0.0.1:5000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - } + # For the backend locations below ("location /" sets its own). + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + + # The API and uploaded files go to the backend. Keep the ^~: without it, any regex location + # (e.g. one that caches *.png or *.css) wins and sends /api/uploads/…/logo.png to the site. + location ^~ /api/ { proxy_pass http://127.0.0.1:5000; } + location ^~ /uploads/ { proxy_pass http://127.0.0.1:5000; } + location ~ ^/(api|uploads|health|docs)(/|$) { proxy_pass http://127.0.0.1:5000; } location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; @@ -147,7 +151,10 @@ server { ``` The VPS nginx/Caddy must redirect plain HTTP to HTTPS and pass the `Host` header through to frps -unchanged (frps picks the site by its host name). For nginx on the VPS, roughly: +unchanged (frps picks the site by its host name). Send every path through as it is: no +`location ~* \.(png|css|js…)$` caching rules for this site on the VPS, which would send +`/api/uploads/…/logo.png` to the site instead of the backend. (Since 3.6.1 the site passes such +requests on to the backend itself, but they're slower that way.) For nginx on the VPS, roughly: ```nginx server { @@ -188,13 +195,17 @@ server { client_max_body_size 25m; access_log /var/log/nginx/hope-events.access.log hope_proxy; - location ~ ^/(api|uploads|health|docs)(/|$) { - proxy_pass http://127.0.0.1:5000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - } + # For the backend locations below ("location /" sets its own). + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + + # The API and uploaded files go to the backend. Keep the ^~: without it, any regex location + # (e.g. one that caches *.png or *.css) wins and sends /api/uploads/…/logo.png to the site. + location ^~ /api/ { proxy_pass http://127.0.0.1:5000; } + location ^~ /uploads/ { proxy_pass http://127.0.0.1:5000; } + location ~ ^/(api|uploads|health|docs)(/|$) { proxy_pass http://127.0.0.1:5000; } location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; diff --git a/apps/events/WHATS-NEW.md b/apps/events/WHATS-NEW.md index adc31e6..8cf38fa 100644 --- a/apps/events/WHATS-NEW.md +++ b/apps/events/WHATS-NEW.md @@ -12,6 +12,12 @@ Write for church admins, not developers: no environment variables, endpoints or developer log is CHANGELOG.md. A tagged version without a section here shows "No details given". --> +## 3.6.1 + +- **Fix:** uploading a logo or site icon under Settings → Branding could fail with "uploaded, but + the site can't show it yet", depending on how the server is set up. Uploaded pictures, certificate + downloads and the like now show on those servers too. + ## 3.6.0 - **People's details are checked every night.** Cross Events compares everyone's name, email, diff --git a/apps/events/backend/package.json b/apps/events/backend/package.json index 444f1e5..f3b12eb 100644 --- a/apps/events/backend/package.json +++ b/apps/events/backend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/events-backend", - "version": "3.6.0", + "version": "3.6.1", "description": "Event Management System Backend", "main": "src/index.js", "scripts": { diff --git a/apps/events/env.template.json b/apps/events/env.template.json index 48c4814..abb0b03 100644 --- a/apps/events/env.template.json +++ b/apps/events/env.template.json @@ -108,6 +108,12 @@ "layer": "install", "from": "https://{domain}", "required": true + }, + { + "name": "BACKEND_INTERNAL_URL", + "layer": "install", + "from": "http://127.0.0.1:{apiPort}", + "description": "The backend on this server: requests for /api or /uploads that reach the site are passed to it (3.6.1)" } ] } diff --git a/apps/events/frontend/next.config.ts b/apps/events/frontend/next.config.ts index 1178671..0c1a24a 100644 --- a/apps/events/frontend/next.config.ts +++ b/apps/events/frontend/next.config.ts @@ -1,6 +1,15 @@ import type { NextConfig } from "next"; import { withSentryConfig } from "@sentry/nextjs"; +// Requests for the backend (/api, /uploads) that reach the site anyway are passed to it (3.6.1). +// On a server nginx sends those paths to the backend, but a proxy in front can send some to the +// site instead: one with a rule for file extensions (static-file caching) sent every +// /api/uploads/…png here, so an uploaded logo never showed. BACKEND_INTERNAL_URL is the backend on +// this server (http://127.0.0.1:), never the public address, which would come straight back +// here. The end-to-end tests set E2E_API_PROXY (3.0.0): the site and its API on one address, as +// nginx does, so Accounts' sign-in comes back to /api/auth/callback. +const backend = (process.env.BACKEND_INTERNAL_URL || process.env.E2E_API_PROXY || "").replace(/\/+$/, ""); + const nextConfig: NextConfig = { // The end-to-end tests run their own dev server; a separate build folder keeps it // from clashing with one already running. @@ -12,10 +21,20 @@ const nextConfig: NextConfig = { compiler: { removeConsole: process.env.NODE_ENV === 'production', }, - // The end-to-end tests only (3.0.0): the site and its API on one address, as nginx does on a - // server, so Accounts' sign-in comes back to /api/auth/callback. Unset everywhere else. - ...(process.env.E2E_API_PROXY - ? { async rewrites() { return [{ source: '/api/:path*', destination: `${process.env.E2E_API_PROXY}/api/:path*` }]; } } + ...(backend + ? { + // beforeFiles: ahead of every page, so a dynamic route like /[redirectUrl] never catches them. + async rewrites() { + return { + beforeFiles: [ + { source: '/api/:path*', destination: `${backend}/api/:path*` }, + { source: '/uploads/:path*', destination: `${backend}/uploads/:path*` }, + ], + afterFiles: [], + fallback: [], + }; + }, + } : {}), }; diff --git a/apps/events/frontend/package.json b/apps/events/frontend/package.json index 41b4dbe..f272525 100644 --- a/apps/events/frontend/package.json +++ b/apps/events/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/events-frontend", - "version": "3.6.0", + "version": "3.6.1", "private": true, "scripts": { "dev": "next dev", diff --git a/apps/events/package.json b/apps/events/package.json index dc0e396..9735119 100644 --- a/apps/events/package.json +++ b/apps/events/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/events", - "version": "3.6.0", + "version": "3.6.1", "main": "index.js", "scripts": { "dev:backend": "cd backend && npm run dev", diff --git a/apps/events/scripts/install.sh b/apps/events/scripts/install.sh index 158edcc..413e07a 100644 --- a/apps/events/scripts/install.sh +++ b/apps/events/scripts/install.sh @@ -116,7 +116,7 @@ else echo " backend/.env exists — kept" fi if [ ! -f "$DIR/frontend/.env.production" ]; then - echo "NEXT_PUBLIC_API_URL=$SITE_URL" > "$DIR/frontend/.env.production" + printf 'NEXT_PUBLIC_API_URL=%s\nBACKEND_INTERNAL_URL=http://127.0.0.1:%s\n' "$SITE_URL" "$API_PORT" > "$DIR/frontend/.env.production" fi if [ ! -f "$DIR/ecosystem.config.js" ]; then sed -e "s/'hope-events-backend'/'$NAME-backend'/" -e "s/'hope-events-frontend'/'$NAME-frontend'/" -e "s/-p 3000/-p $WEB_PORT/" \ @@ -140,14 +140,17 @@ server { server_name $DOMAIN; client_max_body_size 25m; + # For the backend locations below ("location /" sets its own). + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + # The API, uploaded files, health and API docs go to the backend; everything else to the site. - location ~ ^/(api|uploads|health|docs)(/|\$) { - proxy_pass http://127.0.0.1:$API_PORT; - proxy_set_header Host \$host; - proxy_set_header X-Real-IP \$remote_addr; - proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto \$scheme; - } + # ^~ so a regex location added later (e.g. caching *.png) can't send /api/…/logo.png to the site. + location ^~ /api/ { proxy_pass http://127.0.0.1:$API_PORT; } + location ^~ /uploads/ { proxy_pass http://127.0.0.1:$API_PORT; } + location ~ ^/(api|uploads|health|docs)(/|\$) { proxy_pass http://127.0.0.1:$API_PORT; } location / { proxy_pass http://127.0.0.1:$WEB_PORT; proxy_http_version 1.1; diff --git a/docs/HANDOVER.md b/docs/HANDOVER.md index e7b9ea7..7918073 100644 --- a/docs/HANDOVER.md +++ b/docs/HANDOVER.md @@ -45,11 +45,38 @@ and What's New, and [VERSIONS.md](./VERSIONS.md). |---------|------| | `events@3.4.0`, `accounts@1.4.0`, `contracts@1.12.0`, `agent@1.3.0`, Hub `v2.8.0` | Background jobs switched on/off and rescheduled from each site's admin (saved in `job_overrides`, wins over the .env, applies at once; Accounts gets an Admin → Background jobs page). Accounts' emails styled as Events' (`src/lib/emails.ts`). The Hub reads and changes an install's .env (`env-read` / `env-set` jobs → `crosscode env`; secrets never leave the server; the file is put back if the site doesn't start; the frontend's file triggers a rebuild) | | `events@3.5.0`, `contracts@1.13.0`, `agent@1.3.1`, Hub `v2.9.0` | **Fix:** "Load demo data" deleted the Accounts link (`set-demo.js` truncated `ProductLink`), so events-demo couldn't sign anyone in (`ACCOUNTS_UNAVAILABLE`). Demo data keeps the link; a site in Accounts mode without a link reconnects at its next heartbeat. Heartbeat `stats.signIn`; Hub alerts: not linked (critical), wrong Accounts, sign-in failing, an Accounts nothing links to. **Agent 1.3.0 reported itself as 1.2.0**: use 1.3.1 | +| `accounts@1.6.0` | A "New sign-in" email (and WhatsApp) after every sign-in; Sign-in settings → `signin_notices` turns it off | +| `events@3.6.1` | **Fix:** logo/favicon uploads failed on events-demo ("uploaded, but the site can't show it yet"). FastPanel's static-file rule sent every `/api/…` path with a file extension (`.png`, `.pdf`, …) to the frontend. The site now passes `/api/*` and `/uploads/*` on to the backend (`BACKEND_INTERNAL_URL`); the installers' nginx uses `location ^~`. Change each FastPanel site too (below) | | `events@3.6.0`, `accounts@1.5.0`, `contracts@1.14.0` | The nightly people check (`accounts-people-check`, 04:30): `people.check` 500 subs at a time; fixes out-of-date copies, handles deleted accounts as `user.deleted`, stops (changing nothing) when most people are unknown. Skipped with an Accounts before 1.5.0 | **To fix events-demo before it's updated:** its Settings → Linked products → Connect the church's Accounts (or update it to Events 3.5.0+, which reconnects within ~15 minutes). +## FastPanel sites (central server) + +FastPanel's nginx on the central server is the only router for sites behind frp: the church +server has no nginx. Its static-file handling adds a regex location for file extensions +(`png|jpg|ico|svg|css|js|pdf|txt|…`) that falls back to the site's main proxy, the frontend. A +plain `location /api` loses to it, so `/api/uploads/…/logo.png` reached Next.js and got a 404 +(fixed in the site by Events 3.6.1, but slower and without the visitor's IP). In each Events +site's nginx config in FastPanel, the backend locations must be `^~` (a prefix match that no +regex can override): + +```nginx +location ^~ /api/ { + proxy_pass http://127.0.0.1:; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; +} +location = /api { proxy_pass http://127.0.0.1:; } +``` + +The Hub's FastPanel email (AGENT-1.0-PLAN §11) still says just "/api → backend": it should say +`location ^~ /api/`. Check after a change: +`curl -sI https:///api/health.png` must say `X-Powered-By: Express` (a 404 is fine). + ## Next up Nothing from phase 1 onwards is rolled out yet (VERSIONS.md, "Deployed / rolled out"), so roll out diff --git a/docs/VERSIONS.md b/docs/VERSIONS.md index ad56379..33148b8 100644 --- a/docs/VERSIONS.md +++ b/docs/VERSIONS.md @@ -10,13 +10,13 @@ separately below; the two often differ. | What | Repo | Latest | Tag | Released | |------|------|--------|-----|----------| -| Cross Events | `crosscode-platform` (`apps/events`) | **3.6.0** | `events@3.6.0` | 2026-11-20 | +| Cross Events | `crosscode-platform` (`apps/events`) | **3.6.1** | `events@3.6.1` | 2026-11-20 | | Accounts | `crosscode-platform` (`apps/accounts`) | **1.6.0** | `accounts@1.6.0` | 2026-11-20 | | Server agent | `crosscode-platform` (`apps/agent`) | **1.3.1** | `agent@1.3.1` | 2026-11-20 | | Contracts | `crosscode-platform` (`packages/contracts`) | **1.14.0** | `contracts@1.14.0` | 2026-11-20 | | Cross Code Hub | `events-hub` | **2.9.0** | `v2.9.0` | 2026-11-20 | | crosscode.co.za | `crosscode-site` | **1.6.0** | `v1.6.0` | 2026-11-19 | -| `crosscode` script | `crosscode-platform` (`scripts/`) | `main` | none | 2026-11-20 (last change: `crosscode env`) | +| `crosscode` script | `crosscode-platform` (`scripts/`) | `main` | none | 2026-11-20 (last change: nginx `location ^~ /api/`) | The `crosscode` script has no version: every server's copy (`/opt/crosscode/tools`) pulls `main` on each run, so merging to `main` and pushing releases it. Its changes are listed in @@ -37,6 +37,10 @@ need their own tags until something outside this repo depends on them. ## What each latest release was for +- **Events 3.6.1 (fix):** logo and favicon uploads failed on events-demo: FastPanel's static-file + rule sent every `/api/…` path with a file extension to the frontend. The site now passes those on + to the backend. Also change the FastPanel site (HANDOVER.md, "FastPanel sites"). No migration. + - **Accounts 1.6.0:** a "New sign-in" email (and WhatsApp) after every sign-in, as Cross Events' own sign-in sends; admins can turn it off. No migration. diff --git a/package-lock.json b/package-lock.json index 8305831..a3049a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -128,7 +128,7 @@ }, "apps/events/backend": { "name": "@crosscode/events-backend", - "version": "3.6.0", + "version": "3.6.1", "hasInstallScript": true, "dependencies": { "@cj-tech-master/excelts": "^10.2.0", @@ -178,7 +178,7 @@ }, "apps/events/frontend": { "name": "@crosscode/events-frontend", - "version": "3.6.0", + "version": "3.6.1", "dependencies": { "@crosscode/contracts": "*", "@crosscode/seo": "*", diff --git a/scripts/lib/install.sh b/scripts/lib/install.sh index 517a73f..b1dd69d 100644 --- a/scripts/lib/install.sh +++ b/scripts/lib/install.sh @@ -517,15 +517,18 @@ server { server_name $domain; client_max_body_size 25m; + # For the backend locations below ("location /" sets its own). + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + # The API, uploaded files, health and API docs go to the backend; everything else to the site. # (From Events 2.2.0 everything is under /api; the other paths are for older releases.) - location ~ ^/(api|uploads|health|docs)(/|\$) { - proxy_pass http://127.0.0.1:$api; - proxy_set_header Host \$host; - proxy_set_header X-Real-IP \$remote_addr; - proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto \$scheme; - } + # ^~ so a regex location added later (e.g. caching *.png) can't send /api/…/logo.png to the site. + location ^~ /api/ { proxy_pass http://127.0.0.1:$api; } + location ^~ /uploads/ { proxy_pass http://127.0.0.1:$api; } + location ~ ^/(api|uploads|health|docs)(/|\$) { proxy_pass http://127.0.0.1:$api; } location / { proxy_pass http://127.0.0.1:$web; proxy_http_version 1.1;