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

View File

@@ -63,13 +63,14 @@ fn create_server_config(
.service(web::resource("/static/{tail:.*}").route(web::get().to(serve_static_files)))
// API 接口
.service(login) // #[post("/api/login")]
.service(get_weather_details) // #[get("/weather/details")](支持 JWT 或 temp_token公开接口
.service(health_check) // #[get("/health")](公开接口,无需认证)
// 受保护接口JWT
.service(
web::scope("")
.wrap(from_fn(jwt_middleware))
.service(post_weather_data) // #[post("/api/post-weather-data")]
.service(get_weather_brief) // #[get("/api/weather")]
.service(get_weather_details) // #[get("/weather/details")] ← 移入受保护作用域
.service(generate_temp_token_handler) // #[post("/api/generate-temp-token/{resource_id}")]
.service(delete_weather) // #[delete("/api/weather/delete/{id}")]
.service(get_current_user_profile) // #[get("/api/user/profile")]
@@ -164,7 +165,12 @@ async fn main() -> std::io::Result<()> {
info!("Attempting to start server...");
let ports = vec![4433, 8443, 8080, 3000, 8000, 8888];
let is_production = std::env::var("APP_ENV").unwrap_or_else(|_| "development".into()) == "production";
let ports = if is_production {
vec![4433, 8443, 8080, 3000, 8000, 8888]
} else {
vec![8080, 3000, 8000, 8888, 4433, 8443]
};
let mut server: Option<
Pin<Box<dyn std::future::Future<Output = std::io::Result<()>> + Unpin>>,
> = None;
@@ -178,7 +184,7 @@ async fn main() -> std::io::Result<()> {
let http_client_clone = http_client.clone();
let app_state_clone = app_state.clone();
if *port == 443 || *port == 8443 {
if *port == 443 || *port == 8443 || *port == 4433 {
let ssl_builder = match create_ssl_acceptor() {
Ok(builder) => builder,
Err(e) => {