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/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;