Events 3.6.1: branding uploads work behind a proxy with extension rules
The logo/favicon upload succeeded, but the check that the site can show it got a 404: on events-demo every /api/... path ending in a file extension (.png, .ico, .pdf, .json) went to Next.js instead of the backend. - next.config.ts: /api/* and /uploads/* that reach the site are passed to the backend (beforeFiles rewrites) via the new BACKEND_INTERNAL_URL (http://127.0.0.1:<apiPort>, from env.template.json on deploy). The e2e E2E_API_PROXY uses the same rewrites. - nginx written by both installers and shown in DEPLOYMENT.md: /api/ and /uploads/ use location ^~ so no regex location can take them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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:<apiPort>`, 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).
|
||||
|
||||
+26
-15
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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)"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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:<port>), 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 <site>/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 <site>/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: [],
|
||||
};
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/events-frontend",
|
||||
"version": "3.6.0",
|
||||
"version": "3.6.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user