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

73 lines
2.1 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.
echo [检测] 检查端口 8080 ...
:: ── 检查端口 8080 是否已被占用 ──
netstat -ano 2>nul | findstr ":8080" | findstr "LISTENING" >nul
if %errorlevel% equ 0 (
echo [警告] 端口 8080 已被占用!
echo.
echo 请先关闭占用 8080 端口的程序,或者:
echo 1. 任务管理器关闭相关进程
echo 2. 运行: netstat -ano ^| findstr :8080 查看 PID
echo 3. 运行: taskkill /PID ^<PID^> /F 强制结束
:: 尝试直接打开已有的服务
echo.
echo [尝试] 直接打开浏览器访问 http://localhost:8080/ ...
start http://localhost:8080/
pause
exit /b 0
)
:: ── 优先 Python(最稳定,无需联网)──
where python >nul 2>nul
if %errorlevel% equ 0 (
echo [启动] 使用 Python 启动 HTTP 服务器(端口 8080...
echo.
echo ★ 服务器运行中,请勿关闭本窗口 ★
echo 访问地址:http://localhost:8080/
echo 按 Ctrl+C 停止服务器
echo ============================================
echo.
python -m http.server 8080
goto end
)
:: ── 备选 npx serve(需联网下载)──
where npx >nul 2>nul
if %errorlevel% equ 0 (
echo [启动] 使用 npx serve 启动服务器(端口 8080...
echo 首次运行可能需要下载依赖,请稍候...
echo.
echo ★ 服务器运行中,请勿关闭本窗口 ★
echo 访问地址:http://localhost:8080/
echo 按 Ctrl+C 停止服务器
echo ============================================
echo.
npx --yes serve . -p 8080 --no-clipboard
goto end
)
:: ── 都不可用 ──
echo [错误] 未找到 Python 或 Node.js
echo.
echo 请安装以下任一工具:
echo · Python 3: https://www.python.org/downloads/
echo · Node.js: https://nodejs.org/
echo.
pause
exit /b 1
:end
echo.
echo 服务器已停止。
pause