let allowed_origins: AllowedOrigins = AllowedOrigins::all(); //主要是这一句 let allowed_methods: AllowedMethods = ["Get", "Post", "Delete"] .iter() .map(|s| FromStr::from_str(s).unwrap()) .collect(); let allowed_headers: AllowedHeaders = AllowedHeaders::all(); let options = Cors { allowed_origins: allowed_origins, allowed_methods: allowed_methods, allowed_headers: allowed_headers, allow_credentials: true, ..Default::default() }; if options.validate().is_err() { panic!(); }
//载入路由 rocket::custom(config) .mount( "/", routes![ excel::upload_excel, //上传excel文件 ], ) .attach(options) //注册到服务上 .launch();