11// Minimal static + reverse-proxy server for the Docker web container (Dockerfile.web).
22// Serves the web container:
33// - serves static files from /usr/share/nginx/html with SPA fallback to index.html
4- // - proxies /api/* to http://api:3001 (path preserved, body + response streamed)
4+ // - proxies /api/* and /health to http://api:3001 (path preserved, body + response streamed)
55// - generates /runtime-config.js at startup from RUNTIME_* env vars
66// - long-cache headers for /assets/*, no-store for /runtime-config.js
77// Uses only Node built-ins (http, fs, path) so no npm install is needed in the image.
@@ -21,6 +21,7 @@ const jsonStringOrNull = (value) => {
2121 if ( ! trimmed ) return 'null' ;
2222 return JSON . stringify ( trimmed ) ;
2323} ;
24+ const normalizeBackendFlavor = ( value ) => ( trim ( value ) . toLowerCase ( ) === 'vertex' ? 'vertex' : 'aistudio' ) ;
2425
2526function writeRuntimeConfig ( ) {
2627 const config = {
@@ -29,6 +30,8 @@ function writeRuntimeConfig() {
2930 useApiProxy : toBool ( process . env . RUNTIME_USE_API_PROXY ?? 'true' ) ,
3031 apiProxyUrl : JSON . parse ( jsonStringOrNull ( process . env . RUNTIME_API_PROXY_URL ?? '/api/gemini' ) ) ,
3132 pyodideBaseUrl : JSON . parse ( jsonStringOrNull ( process . env . RUNTIME_PYODIDE_BASE_URL ) ) ,
33+ backendFlavor : normalizeBackendFlavor ( process . env . RUNTIME_BACKEND_FLAVOR ) ,
34+ enforceApiConfig : toBool ( process . env . RUNTIME_ENFORCE_API_CONFIG ) ,
3235 } ;
3336 const content = `window.__AMC_RUNTIME_CONFIG__ = ${ JSON . stringify ( { ...( globalThis . __AMC_RUNTIME_CONFIG__ || { } ) , ...config } , null , 2 ) } ;` ;
3437 fs . writeFileSync ( path . join ( ROOT , 'runtime-config.js' ) , content ) ;
@@ -146,7 +149,7 @@ function serveStatic(req, res) {
146149
147150const server = http . createServer ( ( req , res ) => {
148151 const pathname = new URL ( req . url , 'http://localhost' ) . pathname ;
149- if ( pathname === '/api' || pathname . startsWith ( '/api/' ) ) {
152+ if ( pathname === '/health' || pathname === '/ api' || pathname . startsWith ( '/api/' ) ) {
150153 return proxyApi ( req , res ) ;
151154 }
152155 return serveStatic ( req , res ) ;
0 commit comments