#!/bin/sh # ============================================ # Chat Switchboard - Frontend Entrypoint # ============================================ # nginx serves static assets and proxies page # routes to the Go backend for template rendering. # API/WS routes are handled by Ingress directly. # # Environment (required): # BACKEND_URL - Backend service URL # (e.g. "http://switchboard-be:8080") # # Environment (optional): # BASE_PATH - URL prefix (e.g. "/dev", "" for root) # ENVIRONMENT - Environment name for logging # ============================================ set -e BASE_PATH="${BASE_PATH:-}" BACKEND_URL="${BACKEND_URL:?BACKEND_URL is required (e.g. http://switchboard-be:8080)}" ENVIRONMENT="${ENVIRONMENT:-production}" # Read version from VERSION file (baked in at build time) APP_VERSION="dev" if [ -f /VERSION ]; then APP_VERSION=$(cat /VERSION | tr -d '[:space:]') fi # Compute build hash from JS file contents (unique per deploy) BUILD_HASH=$(find /usr/share/nginx/html/js -name '*.js' -exec md5sum {} + 2>/dev/null | sort | md5sum | cut -c1-8) if [ -z "${BUILD_HASH}" ]; then BUILD_HASH=$(date +%s | md5sum | cut -c1-8) fi # ── Inject into index.html (redirect page) ── sed -i \ -e "s|%%BASE_PATH%%|${BASE_PATH}|g" \ -e "s|%%APP_VERSION%%|${APP_VERSION}|g" \ /usr/share/nginx/html/index.html # Inject version and build hash into service worker sed -i \ -e "s|%%APP_VERSION%%|${APP_VERSION}|g" \ -e "s|%%BUILD_HASH%%|${BUILD_HASH}|g" \ /usr/share/nginx/html/sw.js echo "✅ Frontend: BASE_PATH=${BASE_PATH:-/} VERSION=${APP_VERSION} BUILD=${BUILD_HASH} BACKEND=${BACKEND_URL}" # ── Page route proxy blocks ───────────────── page_proxy_block() { local path="$1" cat < /etc/nginx/conf.d/default.conf < /etc/nginx/conf.d/default.conf <