diff --git a/frontend/10-generate-env.sh b/frontend/10-generate-env.sh new file mode 100644 index 0000000..0fbacc6 --- /dev/null +++ b/frontend/10-generate-env.sh @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +TEMPLATE="/etc/env/env.js.template" +TARGET="/usr/share/nginx/html/env.js" + +if [ -f "$TEMPLATE" ]; then + echo "Generating env.js from template with API_BASE=${API_BASE:-/api}" + # Default API_BASE to /api if not provided + : ${API_BASE:=/api} + + cat > "$TARGET" < { + if (typeof window !== "undefined" && window.__ENV__ && window.__ENV__.API_BASE) { + return window.__ENV__.API_BASE; + } + // Default to relative /api path for local/containerized deployments + return "/api"; +}; + +const API_BASE = getApiBase(); export async function getRecipes() { const res = await fetch(`${API_BASE}/recipes`);