#!/bin/sh # ============================================ # Chat Switchboard - Frontend Entrypoint # ============================================ # Injects BASE_PATH into index.html and nginx # config at container startup. Supports path- # based multi-env deployment on a single domain. # # Environment: # BASE_PATH - URL prefix (e.g. "/dev", "/test", or "") # ============================================ set -e BASE_PATH="${BASE_PATH:-}" # Compute base href (needs trailing slash for tag) if [ -z "${BASE_PATH}" ]; then BASE_HREF="/" else BASE_HREF="${BASE_PATH}/" fi # ── Inject into index.html ────────────────── sed -i \ -e "s|%%BASE_PATH%%|${BASE_PATH}|g" \ -e "s|%%BASE_HREF%%|${BASE_HREF}|g" \ /usr/share/nginx/html/index.html echo "✅ Frontend configured: BASE_PATH=${BASE_PATH:-/}" # ── Generate nginx config ─────────────────── # If BASE_PATH is set, serve under that prefix with alias. # If empty, serve from root (default behavior). if [ -z "${BASE_PATH}" ]; then cat > /etc/nginx/conf.d/default.conf <<'NGINX' server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript; location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2)$ { expires 1y; add_header Cache-Control "public, immutable"; } location / { try_files $uri $uri/ /index.html; } # Health check for k8s probes location = /healthz { return 200 'ok'; add_header Content-Type text/plain; } add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; } NGINX else cat > /etc/nginx/conf.d/default.conf <