footprint/start.sh

70 lines
1.5 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
echo "📍 Footprint - 打卡定位系统 - 启动脚本"
echo ""
# 检查 Node.js
if ! command -v node &> /dev/null; then
echo "❌ 未检测到 Node.js请先安装 Node.js 18+"
exit 1
fi
echo "✅ Node.js 版本: $(node -v)"
echo ""
# 检查是否已安装依赖
if [ ! -d "backend/node_modules" ]; then
echo "📦 安装后端依赖..."
cd backend && npm install && cd ..
fi
if [ ! -d "frontend/node_modules" ]; then
echo "📦 安装前端依赖..."
cd frontend && npm install && cd ..
fi
# 检查环境变量
if [ ! -f "backend/.env" ]; then
echo "⚠️ 未检测到 .env 文件,从模板创建..."
cp backend/.env.example backend/.env
echo "📝 请编辑 backend/.env 文件,配置 OAuth2 凭据"
echo ""
fi
# 初始化数据库
echo "🗄️ 初始化数据库..."
cd backend && npm run init-db && cd ..
echo ""
# 启动服务
echo "🚀 启动服务..."
echo ""
# 启动后端
echo "▶️ 启动后端服务 (http://localhost:5000)..."
cd backend && npm run dev &
BACKEND_PID=$!
# 等待后端启动
sleep 3
# 启动前端
echo "▶️ 启动前端服务 (http://localhost:3000)..."
cd frontend && npm start &
FRONTEND_PID=$!
echo ""
echo "✅ 服务已启动!"
echo ""
echo "访问地址:"
echo " - 前端: http://localhost:3000"
echo " - 后端: http://localhost:5000"
echo ""
echo "按 Ctrl+C 停止所有服务"
# 捕获退出信号
trap "kill $BACKEND_PID $FRONTEND_PID; exit" INT TERM
# 等待
wait