fix: 将 get_weather_details 和 health_check 移出 JWT 保护作用域作为公开接口

This commit is contained in:
2026-04-18 14:04:49 +08:00
parent d756694534
commit fd21e641a2
4 changed files with 161 additions and 4 deletions

100
test_deployment.sh Executable file
View File

@@ -0,0 +1,100 @@
#!/bin/bash
set -euo pipefail
DEVELOPMENT_RUST_URL="http://127.0.0.1:8080"
PRODUCTION_DOMAIN="https://xmclassmate.top"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
check_local_backend() {
log_info "测试本地后端服务 (127.0.0.1:8080)..."
local status_code
status_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "${DEVELOPMENT_RUST_URL}/health" 2>/dev/null || echo "000")
if [ "$status_code" = "200" ]; then
log_info "本地后端服务正常 (HTTP $status_code)"
return 0
else
log_error "本地后端服务异常 (HTTP $status_code)"
return 1
fi
}
check_domain_access() {
log_info "测试域名访问 (${PRODUCTION_DOMAIN}/dev)..."
local status_code
status_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 -L -k \
-H "Host: xmclassmate.top" \
"${PRODUCTION_DOMAIN}/dev" 2>/dev/null || echo "000")
if [ "$status_code" = "200" ] || [ "$status_code" = "301" ] || [ "$status_code" = "302" ]; then
log_info "域名访问正常 (HTTP $status_code)"
return 0
else
log_error "域名访问异常 (HTTP $status_code)"
return 1
fi
}
check_static_files() {
log_info "测试静态文件服务..."
local test_files=(
"/static/katex/katex.min.css"
"/static/css/style.css"
"/static/favicon.ico"
)
local failed=0
for file in "${test_files[@]}"; do
local status_code
status_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 -L -k \
-H "Host: xmclassmate.top" \
"${PRODUCTION_DOMAIN}${file}" 2>/dev/null || echo "000")
if [ "$status_code" = "200" ]; then
log_info "静态文件 ${file} 正常 (HTTP $status_code)"
else
log_error "静态文件 ${file} 异常 (HTTP $status_code)"
failed=1
fi
done
return $failed
}
main() {
local failed=0
if ! check_local_backend; then
failed=1
fi
if ! check_domain_access; then
failed=1
fi
if ! check_static_files; then
failed=1
fi
if [ $failed -eq 0 ]; then
log_info "========== 所有测试通过 =========="
exit 0
else
log_error "========== 部分测试失败 =========="
exit 1
fi
}
main "$@"