Files
ProxyPool/script/start.bat
祀梦 eeb16774d7 fix: 更换后端端口 9949 -> 18080 解决 Windows 绑定权限问题
- 修改后端默认端口为 18080
- 更新前端 API 配置支持新端口
- 更新启动/停止脚本端口配置
- 添加 .env 配置文件
2026-04-04 13:37:17 +08:00

89 lines
2.2 KiB
Batchfile

@echo off
chcp 65001 >nul
echo === ProxyPool Startup ===
echo.
set "ROOT_PATH=%~dp0.."
set "BACKEND_PORT=18080"
set "FRONTEND_PORT=9948"
REM 1. Clean processes on ports
echo [1/4] Cleaning old processes...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":%BACKEND_PORT%" ^| findstr "LISTENING"') do (
taskkill /F /PID %%a >nul 2>&1
echo Stopped backend (PID: %%a)
)
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":%FRONTEND_PORT%" ^| findstr "LISTENING"') do (
taskkill /F /PID %%a >nul 2>&1
echo Stopped frontend (PID: %%a)
)
echo Cleanup complete!
echo.
REM 2. Start Backend
echo [2/4] Starting backend (FastAPI)...
if exist "%ROOT_PATH%\venv\Scripts\python.exe" (
set "PYTHON_PATH=%ROOT_PATH%\venv\Scripts\python.exe"
echo Using venv
) else (
set "PYTHON_PATH=python"
echo Using system Python
)
cd /d "%ROOT_PATH%"
set "PYTHONIOENCODING=utf-8"
REM Ensure logs directory exists (used by application logger)
mkdir "%ROOT_PATH%\logs" 2>nul
REM Start backend in background of current console
start /B "" "%PYTHON_PATH%" -u main.py
echo Backend started
echo.
REM 3. Wait for backend
echo [3/4] Waiting for backend...
set RETRY_COUNT=0
set BACKEND_READY=0
:WAIT_LOOP
if %RETRY_COUNT% geq 15 goto WAIT_DONE
REM Use ping instead of timeout for PowerShell compatibility
ping -n 3 127.0.0.1 >nul 2>&1
set /a RETRY_COUNT+=1
REM Try to connect to backend health endpoint
powershell -Command "try { $r = Invoke-RestMethod -Uri 'http://127.0.0.1:18080/health' -TimeoutSec 2 -ErrorAction Stop; exit 0 } catch { exit 1 }" >nul 2>&1
if %errorlevel% equ 0 (
set BACKEND_READY=1
goto WAIT_DONE
)
echo Waiting... (%RETRY_COUNT%/15)
goto WAIT_LOOP
:WAIT_DONE
if %BACKEND_READY% equ 0 (
echo.
echo Backend failed to start within 30 seconds!
echo Check the console output above for errors.
pause
exit /b 1
)
echo Backend is ready!
echo.
REM 4. Start Frontend
echo [4/4] Starting frontend (Vite)...
cd /d "%ROOT_PATH%\WebUI"
start /B "" cmd /c "npm run dev"
cd /d "%ROOT_PATH%"
echo Frontend started
echo.
echo === All services started ===
echo Backend: http://127.0.0.1:18080
echo Frontend: http://localhost:9948
echo.
echo Press any key to close this window (services will keep running).
pause >nul