feat: 增加 YAML 配置与一键启动脚本
This commit is contained in:
@@ -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