feat: 增加 YAML 配置与一键启动脚本
This commit is contained in:
@@ -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:
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user