#!/bin/sh # Start the Angular SSR Node process, then nginx. set -e # Ensure nginx can write to the shared logs directory mkdir -p /logs && chown nginx:nginx /logs # Render nginx config from template sed "s|__API_UPSTREAM__|${API_UPSTREAM}|g" /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf # Render client-side config.json for fallback use envsubst '${API_PUBLIC_URL}' < /usr/share/nginx/html/config.json.template > /usr/share/nginx/html/config.json # Start the Angular SSR server (Node process) in the background # Point at nginx (port 80) so SSR API calls go through the nginx proxy chain # to the upstream backend. Nginx is started after SSR so the chain is complete # by the time the first SSR request actually needs API data. export SSR_API_BASE_URL="http://localhost:80" echo "[entrypoint] Starting Angular SSR server on port 4200..." node /app/server/server.mjs & SSR_PID=$! # Wait for the SSR server to be ready (up to 10 seconds) echo "[entrypoint] Waiting for SSR server to be ready..." for i in $(seq 1 20); do if node -e "require('http').get('http://localhost:4200/', (r) => { process.exit(r.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))" 2>/dev/null; then echo "[entrypoint] SSR server is ready." break fi sleep 0.5 done # Start nginx in the foreground (primary process) echo "[entrypoint] Starting nginx..." exec nginx -g 'daemon off;'