fix:修改脚本

This commit is contained in:
Daniel
2026-03-08 17:23:00 +08:00
parent 890dea096b
commit 06c0e36d92
2 changed files with 25 additions and 4 deletions

View File

@@ -17,12 +17,13 @@ if ! ss -tlnp 2>/dev/null | grep -q ":$PORT "; then
fi
fi
echo "--- 测试 API ---"
# 独立后端路由为 /config无 /api 前缀Nginx 反代后浏览器请求 /api/config
if command -v curl >/dev/null 2>&1; then
resp=$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:${PORT}/api/config" 2>/dev/null)
resp=$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:${PORT}/config" 2>/dev/null)
if [ "$resp" = "200" ]; then
echo "GET /api/config 返回 200服务正常。"
echo "GET /config 返回 200服务正常。"
else
echo "GET /api/config 返回 ${resp},请检查服务。"
echo "GET /config 返回 ${resp},请检查服务。"
fi
else
echo "未安装 curl仅检查了端口监听。"

22
run.sh
View File

@@ -35,6 +35,25 @@ if [ -n "$DEPLOY_DIST" ]; then
echo "[run.sh] 已同步 dist/ 到 $DEPLOY_DIST"
fi
# 释放端口:避免 EADDRINUSE上次进程未退出或多次执行 run.sh
_kill_port() {
if command -v lsof >/dev/null 2>&1; then
pids=$(lsof -t -i ":$API_PORT" 2>/dev/null) || true
if [ -n "$pids" ]; then
echo "[run.sh] 停止占用端口 ${API_PORT} 的进程: $pids"
echo "$pids" | xargs kill 2>/dev/null || true
sleep 1
fi
elif command -v fuser >/dev/null 2>&1; then
if fuser -n tcp "$API_PORT" >/dev/null 2>&1; then
echo "[run.sh] 停止占用端口 ${API_PORT} 的进程..."
fuser -k "$API_PORT/tcp" 2>/dev/null || true
sleep 1
fi
fi
}
_kill_port
# 后台启动 API优先 pm2否则 nohup
if [ -n "$USE_PM2" ] && command -v pm2 >/dev/null 2>&1; then
echo "[run.sh] 使用 pm2 启动 API端口 ${API_PORT}..."
@@ -52,4 +71,5 @@ else
exec bash start-api.sh
fi
echo "[run.sh] 部署完成。前端静态在 dist/API 端口 ${API_PORT}检查: curl -s http://127.0.0.1:${API_PORT}/config"
echo "[run.sh] 部署完成。前端静态在 dist/API 端口 ${API_PORT}"
echo "[run.sh] 检查服务: curl -s http://127.0.0.1:${API_PORT}/config 或 ./check-service.sh"