24 lines
766 B
Bash
24 lines
766 B
Bash
|
|
#!/usr/bin/env bash
|
|||
|
|
# 开发期启动:scripts/dev.sh [端口]
|
|||
|
|
# 后端端口默认取 .env 的 BACKEND_PORT(没有就用 8100);命令行参数优先级更高。
|
|||
|
|
set -euo pipefail
|
|||
|
|
cd "$(dirname "$0")/.."
|
|||
|
|
|
|||
|
|
PORT="${1:-}"
|
|||
|
|
if [ -z "$PORT" ]; then
|
|||
|
|
PORT="$(grep -E '^BACKEND_PORT=' .env 2>/dev/null | tail -1 | cut -d= -f2 | tr -d '[:space:]' || true)"
|
|||
|
|
PORT="${PORT:-8100}"
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
if [ ! -d .venv ]; then
|
|||
|
|
echo ">> 创建虚拟环境"
|
|||
|
|
python3 -m venv .venv
|
|||
|
|
.venv/bin/python -m pip -q install -r requirements.txt
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
echo ">> 迁移数据库"
|
|||
|
|
(cd server && ../.venv/bin/python -m alembic upgrade head)
|
|||
|
|
|
|||
|
|
echo ">> 启动 http://0.0.0.0:${PORT} (文档 /docs)"
|
|||
|
|
cd server && exec ../.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port "$PORT" --reload
|