fix: ensure SSR always fetches fresh assets from database
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
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
This commit is contained in:
1 parent
2ece38e52d
commit
328d067d97
9 files changed
+243
-146
No files matched your search
+28
-7
@@ -13,18 +13,24 @@ log_format kmtn_json escape=json
|
||||
|
||||
access_log /logs/access-$log_date.log kmtn_json;
|
||||
|
||||
upstream ssr_backend {
|
||||
server 127.0.0.1:4200;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# SPA fallback — Angular router handles its own paths
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
# Serve static assets directly from disk (hashed filenames are immutable)
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|map)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# Dynamic sitemap.xml + robots.txt — proxied to the backend so each
|
||||
# Dynamic sitemap.xml + robots.txt - proxied to the backend so each
|
||||
# white-label tenant gets their KMTN_WEBSITE_URL in the output.
|
||||
location = /sitemap.xml {
|
||||
proxy_pass __API_UPSTREAM__/api/sitemap/sitemap.xml;
|
||||
@@ -53,12 +59,27 @@ server {
|
||||
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
|
||||
# Disable caching through the double-proxy chain (NPM → frontend nginx → API)
|
||||
# Without this, browsers cache responses keyed by the HTTPS origin, then send
|
||||
# conditional requests (If-None-Match) that get lost or mismatched in the proxy chain.
|
||||
# Disable caching through the double-proxy chain
|
||||
proxy_cache off;
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate" always;
|
||||
add_header Pragma "no-cache" always;
|
||||
add_header Vary "*" always;
|
||||
}
|
||||
|
||||
# Proxy all page requests to the Angular SSR server.
|
||||
# The SSR server (AngularNodeAppEngine) handles both RenderMode.Server
|
||||
# routes (full on-demand rendering with fresh API data) and serves
|
||||
# prerendered static HTML for RenderMode.Prerender routes.
|
||||
location / {
|
||||
proxy_pass http://ssr_backend;
|
||||
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 $http_x_forwarded_proto;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
|
||||
# SSR responses should not be cached by intermediate proxies
|
||||
proxy_cache off;
|
||||
add_header X-Powered-By "Angular SSR" always;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user