feat: 增加 YAML 配置与一键启动脚本

This commit is contained in:
caoxiaozhu
2026-07-21 16:15:01 +08:00
parent a5fbe5130a
commit 7c38e37b23
15 changed files with 954 additions and 71 deletions

View File

@@ -22,9 +22,9 @@ npm install
npm run dev
```
开发服务器默认运行在 `http://localhost:16801`
后端 API 默认通过 Vite 代理转发到 `http://localhost:17861`(见 `vite.config.ts`
通过根目录 `scripts/start-dev.sh` 启动时,开发服务器端口和后端代理端口来自
`backend/config.yaml``server` 配置。单独运行 `npm run dev` 时默认使用前端
`16801` 和后端 `17861`;可用 `FRONTEND_PORT``BACKEND_PORT` 环境变量覆盖
开发环境默认联调真实后端接口。如需进行隔离前端开发,可显式启用 Mock

View File

@@ -5,6 +5,17 @@ import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from 'node:path'
function configuredPort(name: 'FRONTEND_PORT' | 'BACKEND_PORT', fallback: number) {
const port = Number(process.env[name] ?? fallback)
if (!Number.isInteger(port) || port < 1 || port > 65535) {
throw new Error(`${name} must be an integer between 1 and 65535`)
}
return port
}
const frontendPort = configuredPort('FRONTEND_PORT', 16801)
const backendPort = configuredPort('BACKEND_PORT', 17861)
// https://vite.dev/config/
export default defineConfig({
plugins: [
@@ -22,11 +33,12 @@ export default defineConfig({
},
},
server: {
port: 16801,
port: frontendPort,
strictPort: true,
proxy: {
// Frontend uses /modelTF and proxies to the local five-digit backend port.
// 一键启动脚本会将 YAML 中的后端端口注入当前 Vite 进程。
'/modelTF': {
target: 'http://localhost:17861',
target: `http://127.0.0.1:${backendPort}`,
changeOrigin: true,
},
},