25 lines
825 B
Bash
Executable File
25 lines
825 B
Bash
Executable File
#!/usr/bin/env bash
|
||
# 一键启动:首次运行自动安装依赖并构建前端,然后用一个 Python 进程同时提供 API 与页面。
|
||
set -euo pipefail
|
||
cd "$(dirname "$0")"
|
||
|
||
PORT="${PORT:-8787}"
|
||
DB_PATH="${DB_PATH:-$PWD/backend/panorama.db}"
|
||
export PORT DB_PATH
|
||
|
||
echo "==> 检查 Python 依赖"
|
||
python3 -c "import fastapi, uvicorn" 2>/dev/null || python3 -m pip install -r backend/requirements.txt
|
||
|
||
if [ ! -d frontend/node_modules ]; then
|
||
echo "==> 安装前端依赖(首次较慢)"
|
||
(cd frontend && npm install --no-audit --no-fund)
|
||
fi
|
||
|
||
if [ ! -f frontend/dist/index.html ]; then
|
||
echo "==> 构建前端"
|
||
(cd frontend && npm run build)
|
||
fi
|
||
|
||
echo "==> 启动服务:http://localhost:${PORT} (数据库:${DB_PATH})"
|
||
cd backend && exec python3 -m uvicorn app.main:app --host 0.0.0.0 --port "${PORT}"
|