@@ -83,25 +83,37 @@ echo "✅ Runtime configuration setup complete!"
8383# to the real backend. This writes only a `location` block so the fragment can be
8484# included inside the main server block defined in nginx.conf.
8585echo " 📡 Creating API proxy location fragment (/etc/nginx/conf.d/api-proxy.conf)"
86- cat > /etc/nginx/conf.d/api-proxy.conf << EOF
86+
87+ # Use a single-quoted heredoc so shell variables like $host are not expanded into the file.
88+ # We include a placeholder __BACKEND_BASE_URL__ which we safely replace below with the
89+ # actual runtime value (trimmed of a trailing slash).
90+ cat > /etc/nginx/conf.d/api-proxy.conf << 'EOF '
8791# Dynamically generated by startup.sh - proxies /api/* to the backend provided by VITE_BACKEND_BASE_URL
8892location /api/ {
8993 # Forward to the backend base url. Note: using a full URL here lets nginx
9094 # 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_pass __BACKEND_BASE_URL__ /api/;
96+ proxy_set_header Host $host;
97+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
98+ proxy_set_header X-Forwarded-Proto $scheme;
9599 proxy_http_version 1.1;
96100 proxy_set_header Connection '';
97101 proxy_buffering off; # important for SSE
98102 chunked_transfer_encoding off;
99- proxy_cache_bypass \ $ http_upgrade;
103+ proxy_cache_bypass $http_upgrade;
100104 proxy_read_timeout 3600s;
101105 proxy_send_timeout 3600s;
102106}
103107EOF
104- echo " ✅ Wrote /etc/nginx/conf.d/api-proxy.conf"
108+
109+ # Safely replace placeholder with the configured backend URL. Trim any trailing slash so
110+ # resulting proxy_pass has a single /api/ suffix.
111+ BACKEND=${VITE_BACKEND_BASE_URL:- http:// 127.0.0.1: 4000}
112+ # remove trailing slash if present
113+ BACKEND=${BACKEND%/ }
114+ sed -i " s|__BACKEND_BASE_URL__|${BACKEND} |g" /etc/nginx/conf.d/api-proxy.conf
115+
116+ echo " ✅ Wrote /etc/nginx/conf.d/api-proxy.conf (proxy -> ${BACKEND} /api/)"
105117
106118# Start nginx
107119echo " 🌐 Starting nginx..."
0 commit comments