#!/usr/bin/env bash # 检查本项目的 Node 服务是否启动(默认 API 端口 5599) # 用法: ./check-service.sh [端口],不传端口则用 5599 PORT="${1:-5599}" echo "检查端口 ${PORT} 是否在监听..." if command -v ss >/dev/null 2>&1; then ss -tlnp | grep -E ":$PORT\s" || true elif command -v netstat >/dev/null 2>&1; then netstat -tlnp 2>/dev/null | grep -E ":$PORT\s" || true fi if ! ss -tlnp 2>/dev/null | grep -q ":$PORT "; then if ! netstat -tlnp 2>/dev/null | grep -q ":$PORT "; then echo "端口 ${PORT} 未在监听,服务可能未启动。" echo "启动方式: ./start-api.sh 或 ./run.sh" exit 1 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}/config" 2>/dev/null) if [ "$resp" = "200" ]; then echo "GET /config 返回 200,服务正常。" else echo "GET /config 返回 ${resp},请检查服务。" fi else echo "未安装 curl,仅检查了端口监听。" fi