sword_layers/cors/
config.rs1use console::style;
2use serde::{Deserialize, Serialize};
3
4use crate::DisplayConfig;
5
6#[derive(Clone, Debug, Deserialize, Serialize, Default)]
19pub struct CorsConfig {
20 pub enabled: bool,
21 pub allow_origins: Option<Vec<String>>,
22 pub allow_methods: Option<Vec<String>>,
23 pub allow_headers: Option<Vec<String>>,
24 pub allow_credentials: Option<bool>,
25 pub max_age: Option<u64>,
26
27 #[serde(default)]
28 pub display: bool,
29}
30
31impl DisplayConfig for CorsConfig {
32 fn display(&self) {
33 if !self.display {
34 return;
35 }
36
37 println!("\n{}", style("CORS Configuration:").bold());
38
39 println!(" ↳ Enabled: {}", self.enabled);
40
41 if let Some(origins) = &self.allow_origins {
42 println!(" ↳ Allowed Origins: {origins:?}");
43 }
44
45 if let Some(methods) = &self.allow_methods {
46 println!(" ↳ Allowed Methods: {methods:?}");
47 }
48
49 if let Some(headers) = &self.allow_headers {
50 println!(" ↳ Allowed Headers: {headers:?}");
51 }
52
53 if let Some(credentials) = self.allow_credentials {
54 println!(" ↳ Allow Credentials: {credentials}");
55 }
56
57 if let Some(max_age) = self.max_age {
58 println!(" ↳ Max Age: {max_age}s");
59 }
60 }
61}