Skip to content

Latest commit

 

History

History
173 lines (136 loc) · 3.2 KB

File metadata and controls

173 lines (136 loc) · 3.2 KB

终端启动命令参考

🖥️ 方式一:两个终端窗口(推荐)

第1步:启动后端

打开第一个终端:

# Windows
cd D:\work\baidu-autosave
python web_app.py

# Linux/Mac  
cd /path/to/baidu-autosave
python web_app.py

✅ 看到 Server started at http://0.0.0.0:5000 表示成功

第2步:启动前端

打开第二个终端:

# Windows
cd D:\work\baidu-autosave\frontend
npm install
npm run dev

# Linux/Mac
cd /path/to/baidu-autosave/frontend
npm install  
npm run dev

✅ 看到 Local: http://localhost:3000/ 表示成功

🚀 方式二:一键启动脚本

Windows (PowerShell)

# 项目根目录执行
cd D:\work\baidu-autosave
Start-Process powershell -ArgumentList "-Command", "python web_app.py"
Start-Sleep 3
cd frontend
if (!(Test-Path "node_modules")) { npm install }
npm run dev

Linux/Mac (Bash)

#!/bin/bash
cd /path/to/baidu-autosave
python web_app.py &
BACKEND_PID=$!
sleep 3
cd frontend
[ ! -d "node_modules" ] && npm install
npm run dev
# 停止后端:kill $BACKEND_PID

📋 方式三:Docker 启动

如果已配置 Docker:

# 构建并启动
docker-compose up --build

# 后台运行
docker-compose up -d

🔍 检查服务状态

检查后端(5000端口)

# Windows
netstat -an | findstr :5000

# Linux/Mac
lsof -i :5000
#
netstat -tlnp | grep :5000

检查前端(3000端口)

# Windows
netstat -an | findstr :3000

# Linux/Mac  
lsof -i :3000
#
netstat -tlnp | grep :3000

🛠️ 常用终端命令

停止服务

# 停止前端:Ctrl+C

# 停止后端:Ctrl+C

# 强制停止端口进程
# Windows
netstat -ano | findstr :5000
taskkill /PID <PID> /F

# Linux/Mac
lsof -ti:5000 | xargs kill -9
lsof -ti:3000 | xargs kill -9

查看日志

# 后端日志
tail -f log/web_app_$(date +%Y-%m-%d).log

# 前端日志(开发服务器输出)
# 直接在启动终端查看

重启服务

# 重启后端:Ctrl+C 后重新运行 python web_app.py
# 重启前端:Ctrl+C 后重新运行 npm run dev  

⚡ 快捷命令别名(可选)

.bashrc.profile 中添加:

# 后端启动
alias start-backend='cd /path/to/baidu-autosave && python web_app.py'

# 前端启动  
alias start-frontend='cd /path/to/baidu-autosave/frontend && npm run dev'

# 一键启动
alias start-app='cd /path/to/baidu-autosave && python web_app.py & cd frontend && npm run dev'

Windows PowerShell Profile ($PROFILE) 中添加:

function Start-Backend { cd D:\work\baidu-autosave; python web_app.py }
function Start-Frontend { cd D:\work\baidu-autosave\frontend; npm run dev }
function Start-App { 
    cd D:\work\baidu-autosave
    Start-Process python -ArgumentList "web_app.py"  
    cd frontend
    npm run dev
}

🎯 推荐工作流

  1. 开发时:使用两个终端窗口,方便查看各自日志
  2. 演示时:使用一键启动脚本
  3. 生产时:使用 Docker 或系统服务

📱 移动端测试

启动后可通过局域网IP访问:

# 查看本机IP
# Windows
ipconfig

# Linux/Mac  
ifconfig

然后在手机浏览器访问:http://你的IP:3000