File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- use tower_http:: cors:: { Any , CorsLayer } ;
1+ use axum:: http;
2+ use http:: Method ;
3+ use http:: header:: { AUTHORIZATION , CONTENT_TYPE } ;
4+ use tower_http:: cors:: CorsLayer ;
25
36/// 创建跨域中间件
47pub fn create_layer ( ) -> CorsLayer {
8+ // 定义允许的源
9+ let origins = [
10+ "http://localhost:3000" . parse ( ) . unwrap ( ) ,
11+ "https://exquisitecore.xyz" . parse ( ) . unwrap ( ) ,
12+ "https://www.exquisitecore.xyz" . parse ( ) . unwrap ( ) ,
13+ ] ;
14+
15+ // 定义允许的方法
16+ let methods = [
17+ Method :: GET ,
18+ Method :: POST ,
19+ Method :: PUT ,
20+ Method :: DELETE ,
21+ Method :: OPTIONS ,
22+ ] ;
23+
24+ // 定义允许的头部
25+ let headers = [ AUTHORIZATION , CONTENT_TYPE ] ;
26+
527 CorsLayer :: new ( )
6- . allow_methods ( Any )
7- . allow_headers ( Any )
8- . allow_origin ( Any )
28+ . allow_methods ( methods)
29+ . allow_headers ( headers)
30+ . allow_origin ( origins)
31+ . allow_credentials ( true )
932}
You can’t perform that action at this time.
0 commit comments