AZILS's picture
Upload 323 files
a21c316 verified
// CORS 中间件
use tower_http::cors::{CorsLayer, Any};
use axum::http::Method;
/// 创建 CORS layer
pub fn cors_layer() -> CorsLayer {
CorsLayer::new()
.allow_origin(Any)
.allow_methods([
Method::GET,
Method::POST,
Method::PUT,
Method::DELETE,
Method::HEAD,
Method::OPTIONS,
Method::PATCH,
])
.allow_headers(Any)
.allow_credentials(false)
.max_age(std::time::Duration::from_secs(3600))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cors_layer_creation() {
let _layer = cors_layer();
// Layer 创建成功
assert!(true);
}
}