fix:修复报错

This commit is contained in:
Daniel
2026-03-08 21:52:29 +08:00
parent 2dd1117e51
commit b05ebb80fa
2 changed files with 109 additions and 1 deletions

View File

@@ -25,8 +25,35 @@ function copyDir(srcDir, destDir) {
} }
} }
/** 清空目录内容(不删目录本身),避免 EPERM如宝塔 wwwroot 下 dist 无法 rmSync */
function emptyDir(dir) {
if (!fs.existsSync(dir)) return;
for (const name of fs.readdirSync(dir)) {
const p = path.join(dir, name);
try {
if (fs.statSync(p).isDirectory()) {
fs.rmSync(p, { recursive: true });
} else {
fs.unlinkSync(p);
}
} catch (e) {
if (e.code !== 'EPERM' && e.code !== 'EACCES') throw e;
}
}
}
function main() { function main() {
if (fs.existsSync(DIST)) fs.rmSync(DIST, { recursive: true }); if (fs.existsSync(DIST)) {
try {
fs.rmSync(DIST, { recursive: true });
} catch (e) {
if (e.code === 'EPERM' || e.code === 'EACCES') {
emptyDir(DIST);
} else {
throw e;
}
}
}
fs.mkdirSync(DIST, { recursive: true }); fs.mkdirSync(DIST, { recursive: true });
copyFile(path.join(ROOT, 'index.html'), path.join(DIST, 'index.html')); copyFile(path.join(ROOT, 'index.html'), path.join(DIST, 'index.html'));

81
check-nginx-and-api.sh Normal file
View File

@@ -0,0 +1,81 @@
#!/usr/bin/env bash
# 检查 Nginx 反代配置与本地 API5599是否正常
# 在服务器上执行: ./check-nginx-and-api.sh [Nginx站点配置路径]
# 例: ./check-nginx-and-api.sh /www/server/panel/vhost/nginx/view.airtep.com.conf
PORT="${PORT:-5599}"
NGINX_CONF="${1:-}"
echo "========== 1. 检查 API 是否监听并响应 =========="
if command -v ss >/dev/null 2>&1; then
if ss -tlnp 2>/dev/null | grep -q ":$PORT "; then
echo "端口 ${PORT} 已在监听。"
else
echo "端口 ${PORT} 未在监听,请先执行: ./start-api.sh 或 ./run.sh"
fi
fi
echo ""
echo "---------- curl http://127.0.0.1:${PORT}/config ----------"
if command -v curl >/dev/null 2>&1; then
code=$(curl -s -o /tmp/check-api-config.txt -w "%{http_code}" "http://127.0.0.1:${PORT}/config" 2>/dev/null)
echo "HTTP 状态码: $code"
if [ "$code" = "200" ]; then
echo "响应内容: $(cat /tmp/check-api-config.txt 2>/dev/null | head -c 200)"
echo ""
echo "[OK] 本机 API 正常。"
else
echo "[失败] 本机 API 未返回 200请启动后端: ./start-api.sh"
fi
rm -f /tmp/check-api-config.txt
else
echo "未安装 curl跳过。"
fi
echo ""
echo "========== 2. 检查 Nginx 反代配置 =========="
if [ -z "$NGINX_CONF" ]; then
echo "未传入 Nginx 配置路径。用法: $0 /www/server/panel/vhost/nginx/view.airtep.com.conf"
echo "请确认站点配置中包含:"
echo " location /api {"
echo " proxy_pass http://127.0.0.1:5599/; # 末尾必须有 /,且建议用 127.0.0.1 不用 localhost"
echo " ..."
echo " }"
exit 0
fi
if [ ! -f "$NGINX_CONF" ]; then
echo "文件不存在: $NGINX_CONF"
exit 1
fi
echo "配置文件: $NGINX_CONF"
echo ""
if grep -q "location /api" "$NGINX_CONF"; then
echo "--- location /api 片段 ---"
sed -n '/location \/api/,/^[[:space:]]*}/p' "$NGINX_CONF" | head -15
if grep -A1 "location /api" "$NGINX_CONF" | grep -q "proxy_pass http://127.0.0.1:5599/"; then
echo ""
echo "[OK] proxy_pass 为 http://127.0.0.1:5599/(正确)。"
elif grep -A1 "location /api" "$NGINX_CONF" | grep -q "proxy_pass.*5599"; then
echo ""
echo "[注意] 请将 proxy_pass 改为: http://127.0.0.1:5599/ (末尾加 /,并用 127.0.0.1"
else
echo ""
echo "[注意] 未找到 proxy_pass 到 5599请检查配置。"
fi
else
echo "[失败] 未找到 location /api请添加反代到 5599。"
fi
echo ""
echo "========== 3. 测试经 Nginx 访问 /api/config本机==========="
if command -v curl >/dev/null 2>&1; then
code_nginx=$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1/api/config" -H "Host: view.airtep.com" 2>/dev/null)
echo "curl -H Host:view.airtep.com http://127.0.0.1/api/config => HTTP $code_nginx"
if [ "$code_nginx" = "200" ]; then
echo "[OK] 经 Nginx 反代访问 /api/config 正常。"
else
echo "[注意] 经 Nginx 返回 $code_nginx,请检查 Nginx 配置并重载: nginx -t && nginx -s reload"
fi
fi