#!/usr/bin/env bash # Build release Flutter web for VM hosting. # API URL: shell API_BASE_URL > hosting/hosting.env API_PUBLIC_URL > # server/.env API_BASE_URL > default https://cyberhybridhub.com set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" if [ -f "$ROOT/scripts/flutter-env.sh" ]; then # shellcheck source=/dev/null source "$ROOT/scripts/flutter-env.sh" fi if ! command -v flutter >/dev/null 2>&1; then echo "flutter not found. Install Flutter or set FLUTTER_ROOT, then:" >&2 echo " source scripts/flutter-env.sh" >&2 exit 1 fi _CLI_OVERRIDE="${API_BASE_URL:-}" _load_env_api_url() { local file=$1 [ -f "$file" ] || return 0 local line line="$(grep -E '^API_BASE_URL=' "$file" 2>/dev/null | tail -1 || true)" [ -n "$line" ] || return 0 line="${line#API_BASE_URL=}" line="${line%\"}" line="${line#\"}" printf '%s' "$line" } API_BASE_URL="https://cyberhybridhub.com" # hosting.env wins over server/.env for web builds (server may still say :3000). if [ -f "$ROOT/hosting/hosting.env" ]; then # shellcheck source=/dev/null source "$ROOT/hosting/hosting.env" API_BASE_URL="${API_PUBLIC_URL:-$API_BASE_URL}" fi _server_api="$(_load_env_api_url "$ROOT/server/.env")" if [ -n "$_server_api" ] && [ ! -f "$ROOT/hosting/hosting.env" ]; then API_BASE_URL="$_server_api" fi if [ -n "$_CLI_OVERRIDE" ]; then API_BASE_URL="$_CLI_OVERRIDE" fi if [[ "$API_BASE_URL" == http://* ]] || [[ "$API_BASE_URL" == *:3000* ]]; then echo "ERROR: Production web must not use HTTP or port 3000 in API_BASE_URL." >&2 echo " Got: $API_BASE_URL" >&2 echo " Set API_PUBLIC_URL=https://cyberhybridhub.com in hosting/hosting.env" >&2 exit 1 fi echo "Building release web with API_BASE_URL=$API_BASE_URL" _flutter_pub_flag=() if [ "${SKIP_PUB_GET:-0}" = "1" ]; then _flutter_pub_flag=(--no-pub) echo "SKIP_PUB_GET=1 — not running flutter pub get" fi flutter build web --release "${_flutter_pub_flag[@]}" \ --dart-define=API_BASE_URL="$API_BASE_URL" \ --dart-define=AUTH_VERBOSE_LOG=true if [ -x "$ROOT/scripts/copy_flutter_js_source_map.sh" ]; then "$ROOT/scripts/copy_flutter_js_source_map.sh" "$ROOT/build/web" || true fi if [ -x "$ROOT/scripts/stamp-web-cache-bust.sh" ]; then "$ROOT/scripts/stamp-web-cache-bust.sh" fi echo "Done: $ROOT/build/web"