fix: trust proxy forwarded headers so login works behind Caddy

Behind Jambotron's Caddy the app saw http while the browser used https,
so same-domain requests looked cross-origin and @CrossOrigin answered
403 on /api/auth/signin. server.forward-headers-strategy=framework makes
the app use X-Forwarded-Proto/Host; app.origin can be set via APP_ORIGIN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 22:29:31 +02:00
co-authored by Claude Opus 5.5
parent b28f2a8b9c
commit 7f2c1ec282
2 changed files with 14 additions and 2 deletions
+7 -1
View File
@@ -1,3 +1,9 @@
# Схема исходного запроса: за Caddy (https) — из его X-Forwarded-Proto, иначе своя
map $http_x_forwarded_proto $forwarded_proto {
default $http_x_forwarded_proto;
"" $scheme;
}
server {
listen 80;
server_name _;
@@ -12,7 +18,7 @@ server {
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;
proxy_set_header X-Forwarded-Proto $forwarded_proto;
}
# Маршруты Angular (/admin, /tutorials/1 ...) отдаём через index.html
+7 -1
View File
@@ -24,4 +24,10 @@ app:
# Совпадает со сроком жизни cookie (24 ч), иначе UI считает пользователя вошедшим, а API отвечает 401
jwtExpirationMs: 86400000
jwtCookieName: demo-decoupled
origin: http://localhost:4200
# Разрешённый origin для запросов с другого домена (dev-сервер Angular). UI через nginx фронта CORS не касается
origin: ${APP_ORIGIN:http://localhost:4200}
# За обратным прокси (nginx фронта, Caddy Jambotron) приложение видит http. Без X-Forwarded-Proto/Host
# запросы со своего https-домена выглядят кросс-доменными, и CORS отвечает на них 403
server:
forward-headers-strategy: framework