#!/usr/bin/env bash # 啟動 gateway + vite(需 infra 已 up、已 migrate) set -euo pipefail # shellcheck source=_common.sh source "$(cd "$(dirname "$0")" && pwd)/_common.sh" load_env require_cmd go require_cmd npm [[ -x "$BACKEND_DIR/bin/gateway" ]] || { log "gateway binary missing — building…" "$DEPLOY_DIR/scripts/build.sh" } # 停舊再起 "$DEPLOY_DIR/scripts/stop.sh" || true load_env # Public web base for mails export PUBLIC_WEB_BASE="${PUBLIC_WEB_BASE:-http://127.0.0.1:${WEB_PORT}}" log "start gateway :${GATEWAY_PORT}…" cd "$BACKEND_DIR" # Port 由 yaml 預設 8888;可用 PORT 覆寫 export PORT="${GATEWAY_PORT}" nohup ./bin/gateway -f etc/gateway.yaml >"$LOG_GATEWAY" 2>&1 & echo $! >"$PID_GATEWAY" sleep 1 if ! pid_alive "$(cat "$PID_GATEWAY")"; then tail -30 "$LOG_GATEWAY" || true die "gateway failed — see $LOG_GATEWAY" fi # ping for i in $(seq 1 20); do if curl -sf "http://127.0.0.1:${GATEWAY_PORT}/api/v1/ping" >/dev/null 2>&1; then log "gateway ping ok" break fi [[ "$i" -eq 20 ]] && { tail -40 "$LOG_GATEWAY"; die "gateway not responding"; } sleep 0.3 done log "start web :${WEB_PORT}…" cd "$WEB_DIR" nohup npm run dev -- --host 0.0.0.0 --port "${WEB_PORT}" >"$LOG_WEB" 2>&1 & echo $! >"$PID_WEB" sleep 2 if ! curl -sf "http://127.0.0.1:${WEB_PORT}/" >/dev/null 2>&1; then log "web still starting… (check $LOG_WEB)" fi log "=== running ===" log " Web: http://127.0.0.1:${WEB_PORT}/" log " API: http://127.0.0.1:${GATEWAY_PORT}/api/v1/ping" log " Public: ${PUBLIC_WEB_BASE:-}" log " Assets: ${HAIXUN_STORAGE_S3_PUBLIC_BASE_URL:-}/…" log " Mailpit: http://127.0.0.1:${MAILPIT_UI_PORT:-8025}" log " MinIO: http://127.0.0.1:${MINIO_CONSOLE_PORT:-9001}" log " logs: $RUN_DIR/" log " FE 請切 Live 資料來源;seed: admin@30cm.net / admin123(見 migration)"