所有端点都注册在 /api/v1 前缀下:
- GET
/api/v1/pipelines- 获取所有流水线列表 - POST
/api/v1/pipelines- 创建新流水线 - GET
/api/v1/pipelines/{pipeline_id}- 获取流水线详情 - POST
/api/v1/pipelines/{pipeline_id}/scan- 上传图片并识别 - GET
/api/v1/pipelines/{pipeline_id}/export- 导出 Excel 文件 - POST
/api/v1/scan-result- 外部系统推送识别结果(预留)
- ✅ baseURL:
/api/v1 - ✅ 通过 Vite 代理到
http://localhost:8000 - ✅ 响应拦截器自动提取
response.data - ✅ 错误处理统一返回错误消息
- ✅
/api代理到http://localhost:8000 - ✅
changeOrigin: true支持跨域
- ✅
getPipelines()→ GET/api/v1/pipelines - ✅
createPipeline(name)→ POST/api/v1/pipelines - ✅
getPipeline(id)→ GET/api/v1/pipelines/{id} - ✅
scanImage(pipelineId, imageFile)→ POST/api/v1/pipelines/{id}/scan - ✅
exportExcel(pipelineId)→ GET/api/v1/pipelines/{id}/export
所有 API 调用路径与后端端点完全匹配 ✅
- ✅ 使用 Taro.request 进行 HTTP 请求
- ✅ 使用 Taro.uploadFile 进行文件上传
- ✅ API_BASE_URL 通过 defineConstants 注入
- ✅ 错误处理统一返回错误消息
- ✅
config/dev.js- 开发环境:http://localhost:8000/api/v1 - ✅
config/prod.js- 生产环境:https://matriq.example.com/api/v1 - ✅
config/index.js- 主配置文件
- ✅
getPipelines()→ GET/pipelines - ✅
createPipeline(name)→ POST/pipelines - ✅
getPipeline(id)→ GET/pipelines/{id} - ✅
scanImage(pipelineId, filePath)→ POST/pipelines/{id}/scan
所有 API 调用路径与后端端点完全匹配 ✅
- ✅ 确保后端服务运行在
http://localhost:8000 - ✅ 确保
.env文件配置了 PaddleOCR API 信息 - ✅ 确保数据库目录存在:
backend/data/
- ✅ 安装依赖:
cd frontend && npm install - ✅ 启动开发服务器:
npm run dev - ✅ 访问:
http://localhost:3000 - ✅ Vite 会自动代理
/api请求到后端
- ✅ 安装依赖:
cd miniprogram && npm install - ✅ 启动开发:
npm run dev:weapp - ✅ 在微信开发者工具中打开
dist目录 ⚠️ 重要:需要在微信公众平台配置服务器域名:- request 合法域名:
http://localhost:8000(开发环境) - uploadFile 合法域名:
http://localhost:8000(开发环境)
- request 合法域名:
curl http://localhost:8000/
# 应该返回: {"status":"ok","app":"MatriQ OCR Service"}# 获取流水线列表
curl http://localhost:8000/api/v1/pipelines
# 创建流水线
curl -X POST http://localhost:8000/api/v1/pipelines \
-H "Content-Type: application/json" \
-d '{"name":"测试流水线"}'启动前端后,在浏览器控制台执行:
fetch('/api/v1/pipelines')
.then(r => r.json())
.then(console.log)- CORS 跨域:后端需要配置 CORS 中间件(如果前端直接访问,不通过代理)
- 小程序域名:小程序必须配置合法域名才能访问 API
- 文件上传:小程序使用
Taro.uploadFile,Web 使用FormData - 环境变量:小程序通过
defineConstants注入,不是process.env
所有 API 调用配置已正确匹配,可以正常运行!
- ✅ 后端端点定义完整
- ✅ Web 前端 API 封装正确,代理配置正确
- ✅ 小程序 API 封装正确,构建配置正确
- ✅ 所有路径和参数匹配