CI Pipeline / backend-test (push) Successful in 5m31s
CI Pipeline / frontend-test (push) Successful in 23s
CI Pipeline / frontend-build (push) Failing after 27s
CI Pipeline / backend-lint (push) Successful in 8s
CI Pipeline / backend-test (pull_request) Successful in 5m24s
CI Pipeline / frontend-test (pull_request) Successful in 23s
CI Pipeline / frontend-build (pull_request) Failing after 27s
CI Pipeline / backend-lint (pull_request) Successful in 8s
CI Pipeline / quality-gate (push) Successful in 2s
CI Pipeline / quality-gate (pull_request) Successful in 2s
Root cause: Dockerfile copied only browser/ to nginx; server/server.mjs was built but never deployed or executed. Prerender baked DEFAULT_CONFIG into static HTML with no API at build time, causing stale content on every initial paint. Changes: - Dockerfile: serve stage uses node:22-alpine, installs nginx via apk, copies both browser/ and server/ bundles from build stage - docker-entrypoint.sh: starts Angular SSR Node process on port 4200, waits for readiness, exports SSR_API_BASE_URL, then exec nginx - nginx.conf.template: adds upstream ssr_backend block (127.0.0.1:4200), proxies / to SSR backend, static assets served directly with 1y cache - app.server.routes.ts: all routes switched from RenderMode.Prerender to RenderMode.Server for zero stale content - server.ts: removed dead prerender code (PRERENDERED_ROUTES, isPrerenderedRoute, allowStaticRouteRender) - main.server.ts: injects SSR-aware apiBaseUrl via APP_CONFIG (reads SSR_API_BASE_URL env var) - server.spec.ts: updated 5 test suites + added 5 new suites (31 tests) covering server.ts cleanup, RenderMode.Server, entrypoint lifecycle, Dockerfile build, nginx upstream proxy, and API URL injection - vitest.config.ts: added server.spec.ts to include pattern Request flow: Browser -> nginx (port 80) -> SSR server (port 4200) -> Angular SSR -> HttpClient -> localhost:80/api/station-config -> nginx proxies to api:8000 -> fresh data rendered in HTML
36 lines
1.4 KiB
Bash
36 lines
1.4 KiB
Bash
#!/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;'
|