Files
platform-prototype/启动服务器.bat
T

63 lines
1.7 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
title 健康CQ原型 - 本地服务器
cd /d "%~dp0"
echo ============================================
echo 健康CQ升级项目 · 高保真交互原型
echo ============================================
echo.
:: ── 检查端口 8080 是否已被占用 ──
netstat -ano 2>nul | findstr ":8080" | findstr "LISTENING" >nul
if %errorlevel% equ 0 (
echo [跳过] 端口 8080 已被占用,服务器已在运行。
goto open_browser
)
:: ── 优先 npx serve(配置了 serve.json),备选 Python ──
where npx >nul 2>nul
if %errorlevel% equ 0 (
echo [启动] 使用 npx serve 启动服务器...
start "健康CQ原型-服务器" /min cmd /c "npx --yes serve . -p 8080 --no-clipboard"
goto wait_server
)
where python >nul 2>nul
if %errorlevel% equ 0 (
echo [启动] 使用 Python 启动服务器...
start "健康CQ原型-服务器" /min cmd /c "python -m http.server 8080"
goto wait_server
)
echo [错误] 未找到 Node.js (npx) 或 Python
echo 请安装 Node.js: https://nodejs.org/
pause
exit /b 1
:wait_server
echo [等待] 服务器启动中...
set /a COUNT=0
:wait_loop
set /a COUNT+=1
powershell -NoProfile -Command "try {$r=Invoke-WebRequest -Uri 'http://localhost:8080/' -TimeoutSec 2 -UseBasicParsing; exit 0} catch {exit 1}" >nul 2>&1
if %errorlevel% equ 0 (
echo [就绪] 启动成功!(%COUNT%秒)
goto open_browser
)
if %COUNT% geq 30 (
echo [超时] 30秒未就绪,请检查是否被防火墙拦截
pause
exit /b 1
)
timeout /t 1 /nobreak >nul
goto wait_loop
:open_browser
echo [打开] 打开浏览器...
start http://localhost:8080/
echo.
echo ✅ 完成!以后双击本文件即可一键启动。
timeout /t 2 /nobreak >nul
exit