Skip to content

Commit 936b656

Browse files
committed
chore(runtime): include runtime location fragments; write location-only api-proxy fragment for /api to preserve SSE
1 parent 9dcbb78 commit 936b656

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

nginx.conf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ events {
55
http {
66
include /etc/nginx/mime.types;
77
default_type application/octet-stream;
8-
# Allow additional runtime-injected virtual host fragments (created by /startup.sh)
9-
include /etc/nginx/conf.d/*.conf;
10-
118
server {
129
listen 80;
1310
server_name localhost;
1411
root /usr/share/nginx/html;
1512
index index.html;
13+
# Allow additional runtime-injected location fragments (created by /startup.sh)
14+
# These fragments should contain only `location` blocks so they are applied
15+
# to this server instance (for example: location /api/ { ... }).
16+
include /etc/nginx/conf.d/*.conf;
1617

1718
# Handle client-side routing
1819
location / {

startup.sh

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,26 @@ fi
7979

8080
echo "✅ Runtime configuration setup complete!"
8181

82-
# Create an api-proxy config so the container can forward /api requests to the real backend
83-
echo "📡 Creating API proxy config (/etc/nginx/conf.d/api-proxy.conf)"
82+
# Create an api-proxy location fragment so the container can forward /api requests
83+
# to the real backend. This writes only a `location` block so the fragment can be
84+
# included inside the main server block defined in nginx.conf.
85+
echo "📡 Creating API proxy location fragment (/etc/nginx/conf.d/api-proxy.conf)"
8486
cat > /etc/nginx/conf.d/api-proxy.conf << EOF
8587
# Dynamically generated by startup.sh - proxies /api/* to the backend provided by VITE_BACKEND_BASE_URL
86-
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=one:10m max_size=100m inactive=60m;
87-
upstream backend_api {
88-
server ${VITE_BACKEND_BASE_URL};
89-
}
90-
91-
server {
92-
listen 127.0.0.1:8080; # internal server used for proxy fragment only
93-
94-
# Proxy any /api requests to the configured backend. This preserves SSE
95-
location /api/ {
96-
proxy_pass ${VITE_BACKEND_BASE_URL}/api/;
97-
proxy_set_header Host $host;
98-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
99-
proxy_set_header X-Forwarded-Proto $scheme;
100-
proxy_http_version 1.1;
101-
proxy_set_header Connection '';
102-
proxy_buffering off; # important for SSE
103-
chunked_transfer_encoding off;
104-
proxy_cache_bypass $http_upgrade;
105-
proxy_read_timeout 3600s;
106-
proxy_send_timeout 3600s;
107-
}
88+
location /api/ {
89+
# Forward to the backend base url. Note: using a full URL here lets nginx
90+
# perform an external proxy pass to the backend host configured at runtime.
91+
proxy_pass ${VITE_BACKEND_BASE_URL}/api/;
92+
proxy_set_header Host $host;
93+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
94+
proxy_set_header X-Forwarded-Proto $scheme;
95+
proxy_http_version 1.1;
96+
proxy_set_header Connection '';
97+
proxy_buffering off; # important for SSE
98+
chunked_transfer_encoding off;
99+
proxy_cache_bypass $http_upgrade;
100+
proxy_read_timeout 3600s;
101+
proxy_send_timeout 3600s;
108102
}
109103
EOF
110104
echo "✅ Wrote /etc/nginx/conf.d/api-proxy.conf"

0 commit comments

Comments
 (0)