feat: 添加系统设置中修改前端端口并自动重启功能
- 后端:添加 frontend_port 配置项和重启API - 前端:添加端口设置表单和自动重启交互 - 添加前端服务管理脚本支持启动/停止/重启 - 优化重启流程,避免Network Error提示
This commit is contained in:
+29
-2
@@ -1,12 +1,39 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// 从配置文件或环境变量获取端口
|
||||
const getFrontendPort = () => {
|
||||
// 优先级:环境变量 > 配置文件 > 默认值
|
||||
if (process.env.FRONTEND_PORT) {
|
||||
return parseInt(process.env.FRONTEND_PORT, 10);
|
||||
}
|
||||
|
||||
// 尝试读取配置文件
|
||||
const configPath = path.resolve(__dirname, '.frontend-port');
|
||||
if (fs.existsSync(configPath)) {
|
||||
try {
|
||||
const port = parseInt(fs.readFileSync(configPath, 'utf-8').trim(), 10);
|
||||
if (!isNaN(port) && port > 0 && port < 65536) {
|
||||
return port;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('读取前端端口配置文件失败,使用默认端口 3000');
|
||||
}
|
||||
}
|
||||
|
||||
return 3000;
|
||||
};
|
||||
|
||||
const port = getFrontendPort();
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
assetsInclude: ['**/*.hdr', '**/*.woff2'],
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 3000,
|
||||
port: port,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8000',
|
||||
@@ -46,4 +73,4 @@ export default defineConfig({
|
||||
optimizeDeps: {
|
||||
include: ['antd', '@ant-design/icons', 'axios', 'react-router-dom']
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user