@echo off setlocal chcp 65001 >nul echo ======================================== echo 启动 KiroProxy 服务... echo ======================================== set PORT=6696 :: 设置数据库连接 (可选,留空则使用本地存储) :: 示例: mysql://user:password@db4free.net:3306/dbname :: 如果你已在系统环境变量中设置 DATABASE_URL,这里不会覆盖 if not defined DATABASE_URL set DATABASE_URL= :: 设置管理员密码 (可选,留空则不需要登录) :: 设置后访问管理面板需要输入密码 :: 如果你已在系统环境变量中设置 ADMIN_PASSWORD,这里不会覆盖 if not defined ADMIN_PASSWORD set ADMIN_PASSWORD= :: 查找 Python 命令(优先 python,其次 py -3) where python >nul 2>&1 if %errorlevel% equ 0 ( set PYTHON=python ) else ( where py >nul 2>&1 if %errorlevel% equ 0 ( set PYTHON=py -3 ) else ( echo 未找到 Python,请先安装 Python 并加入 PATH goto end ) ) echo [1/3] 正在启动服务... (PORT=%PORT%) start "" /B %PYTHON% run.py %PORT% echo [2/3] 等待服务就绪... set /a count=0 set /a max_attempts=30 :check_service set /a count+=1 echo 检查服务状态... (%count%/%max_attempts%) :: 使用 curl 检查服务是否可用 (如果没有curl则使用powershell) curl -s -o nul -w "%%{http_code}" http://127.0.0.1:%PORT% 2>nul | findstr "200" >nul if %errorlevel% equ 0 ( echo [3/3] 服务已就绪,正在打开网页... timeout /t 1 /nobreak >nul start http://127.0.0.1:%PORT% echo. echo ======================================== echo KiroProxy 启动完成! echo 网页地址: http://127.0.0.1:%PORT% echo ======================================== goto end ) :: 如果curl不可用,使用PowerShell进行检查 powershell -Command "try { $response = Invoke-WebRequest -Uri 'http://127.0.0.1:%PORT%' -TimeoutSec 2 -UseBasicParsing; if ($response.StatusCode -eq 200) { exit 0 } else { exit 1 } } catch { exit 1 }" >nul 2>&1 if %errorlevel% equ 0 ( echo [3/3] 服务已就绪,正在打开网页... timeout /t 1 /nobreak >nul start http://127.0.0.1:%PORT% echo. echo ======================================== echo KiroProxy 启动完成! echo 网页地址: http://127.0.0.1:%PORT% echo ======================================== goto end ) if %count% lss %max_attempts% ( timeout /t 2 /nobreak >nul goto check_service ) echo. echo ======================================== echo 警告: 服务启动超时 echo 请手动访问: http://127.0.0.1:%PORT% echo ======================================== :end if "%KIROPROXY_NO_PAUSE%"=="1" exit /b 0 pause endlocal