143 lines
3.2 KiB
Markdown
143 lines
3.2 KiB
Markdown
|
|
# 幼儿阅读教学服务平台 - 服务启动指南
|
|||
|
|
|
|||
|
|
## 📋 概述
|
|||
|
|
|
|||
|
|
本项目已配置统一的启动脚本,解决了因工作目录不一致导致的服务启动问题。
|
|||
|
|
|
|||
|
|
## 🚀 快速启动
|
|||
|
|
|
|||
|
|
### 方式一:统一启动(推荐)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 启动所有服务(后端 + 前端)
|
|||
|
|
./start-all.sh
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
这将:
|
|||
|
|
- ✅ 自动切换到正确的目录
|
|||
|
|
- ✅ 检查端口占用(3000 和 5173)
|
|||
|
|
- ✅ 自动安装依赖(如果需要)
|
|||
|
|
- ✅ 后台启动所有服务
|
|||
|
|
- ✅ 等待服务就绪
|
|||
|
|
- ✅ 显示访问地址和日志位置
|
|||
|
|
|
|||
|
|
### 方式二:分别启动
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 启动后端
|
|||
|
|
./reading-platform-backend/start-backend.sh
|
|||
|
|
|
|||
|
|
# 启动前端
|
|||
|
|
./reading-platform-frontend/start-frontend.sh
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 🛑 停止服务
|
|||
|
|
|
|||
|
|
### 统一停止
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
./stop-all.sh
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 手动停止
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 停止后端
|
|||
|
|
lsof -ti:3000 | xargs kill -9
|
|||
|
|
|
|||
|
|
# 停止前端
|
|||
|
|
lsof -ti:5173 | xargs kill -9
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📍 访问地址
|
|||
|
|
|
|||
|
|
启动成功后,可以访问:
|
|||
|
|
|
|||
|
|
| 服务 | 地址 | 说明 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| 前端页面 | http://localhost:5173 | Vue 前端应用 |
|
|||
|
|
| 后端 API | http://localhost:3000 | NestJS 后端 API |
|
|||
|
|
| API 路由 | http://localhost:3000/api/v1 | API 基础路径 |
|
|||
|
|
|
|||
|
|
## 📊 查看日志
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 实时查看后端日志
|
|||
|
|
tail -f /tmp/reading-platform-backend.log
|
|||
|
|
|
|||
|
|
# 实时查看前端日志
|
|||
|
|
tail -f /tmp/reading-platform-frontend.log
|
|||
|
|
|
|||
|
|
# 查看所有日志
|
|||
|
|
tail -f /tmp/reading-platform-*.log
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 🔍 检查服务状态
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 检查后端是否运行
|
|||
|
|
lsof -ti:3000
|
|||
|
|
|
|||
|
|
# 检查前端是否运行
|
|||
|
|
lsof -ti:5173
|
|||
|
|
|
|||
|
|
# 测试后端 API
|
|||
|
|
curl http://localhost:3000/api/v1/courses
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📂 目录结构
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
/Users/retirado/ccProgram/
|
|||
|
|
├── start-all.sh # 统一启动脚本 ⭐
|
|||
|
|
├── stop-all.sh # 统一停止脚本 ⭐
|
|||
|
|
├── reading-platform-backend/ # 后端目录
|
|||
|
|
│ ├── start-backend.sh # 后端启动脚本
|
|||
|
|
│ ├── package.json
|
|||
|
|
│ └── src/
|
|||
|
|
└── reading-platform-frontend/ # 前端目录
|
|||
|
|
├── start-frontend.sh # 前端启动脚本
|
|||
|
|
├── package.json
|
|||
|
|
└── src/
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## ⚠️ 常见问题
|
|||
|
|
|
|||
|
|
### Q: 端口被占用怎么办?
|
|||
|
|
A: 统一启动脚本会自动检测并提示是否停止占用端口的进程。
|
|||
|
|
|
|||
|
|
### Q: 如何重启服务?
|
|||
|
|
A: 先运行 `./stop-all.sh` 停止服务,再运行 `./start-all.sh` 启动。
|
|||
|
|
|
|||
|
|
### Q: 服务启动失败怎么办?
|
|||
|
|
A: 查看日志文件排查问题:
|
|||
|
|
```bash
|
|||
|
|
tail -f /tmp/reading-platform-backend.log
|
|||
|
|
tail -f /tmp/reading-platform-frontend.log
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Q: 如何在开发模式下启动?
|
|||
|
|
A: 脚本默认就是开发模式(`npm run dev` / `npm run start:dev`)。
|
|||
|
|
|
|||
|
|
## 🎯 开发建议
|
|||
|
|
|
|||
|
|
1. **首次使用**:运行 `./start-all.sh` 启动所有服务
|
|||
|
|
2. **日常开发**:直接使用 IDE 的自动保存和热重载功能
|
|||
|
|
3. **遇到问题**:查看 `/tmp/reading-platform-*.log` 日志文件
|
|||
|
|
4. **停止开发**:运行 `./stop-all.sh` 停止所有服务
|
|||
|
|
|
|||
|
|
## 📝 脚本特性
|
|||
|
|
|
|||
|
|
- ✅ 自动目录切换(无需担心工作目录问题)
|
|||
|
|
- ✅ 端口占用检测和提示
|
|||
|
|
- ✅ 依赖自动安装
|
|||
|
|
- ✅ 后台运行服务
|
|||
|
|
- ✅ 服务健康检查
|
|||
|
|
- ✅ 日志文件管理
|
|||
|
|
- ✅ 友好的进度提示
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
**创建时间**: 2026-02-10
|
|||
|
|
**版本**: 1.0
|