更新
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
# 生产模式:确保前端已构建,单端口提供 Web + API
|
||||
# 兼容:install.sh 自建的 .venv / 宝塔 Python 项目环境
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-$ROOT/playwright-browsers}"
|
||||
export KEFU_SERVE_WEB="${KEFU_SERVE_WEB:-true}"
|
||||
export KEFU_STATIC_DIR="${KEFU_STATIC_DIR:-$ROOT/frontend/dist}"
|
||||
|
||||
PY=""
|
||||
if [ -x "$ROOT/backend/.venv/bin/python" ]; then
|
||||
PY="$ROOT/backend/.venv/bin/python"
|
||||
elif command -v python &>/dev/null; then
|
||||
PY="$(command -v python)"
|
||||
fi
|
||||
|
||||
if [ -z "$PY" ]; then
|
||||
echo "[错误] 未找到 Python,请运行 ./install.sh 或在宝塔配置 Python 项目"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$ROOT/frontend/dist/index.html" ]; then
|
||||
echo "[System] 未找到 frontend/dist,正在构建前端..."
|
||||
cd "$ROOT/frontend"
|
||||
npm install --no-fund --no-audit
|
||||
npm run build
|
||||
cd "$ROOT"
|
||||
fi
|
||||
|
||||
HOST="${KEFU_HOST:-0.0.0.0}"
|
||||
PORT="${KEFU_PORT:-8000}"
|
||||
|
||||
echo "[System] Starting Web service (API + UI)..."
|
||||
echo "[System] Python: $PY"
|
||||
echo "[System] URL: http://${HOST}:${PORT}"
|
||||
echo
|
||||
|
||||
cd "$ROOT/backend"
|
||||
exec "$PY" -m uvicorn main:app --host "$HOST" --port "$PORT"
|
||||
Reference in New Issue
Block a user