File size: 718 Bytes
a21c316 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // 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);
}
}
|