A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 335b6ece55f3461f7137c795d7d3e54dcabc36b1 (644 bytes)[doc][blame][raw]
1
pub struct CorsMiddleware {2
origin: String,3
}5
impl CorsMiddleware {6
pub fn new(origin: &str) -> Self {7
Self { origin: origin.into() }8
}9
}11
#[tide::utils::async_trait]12
impl<State: Clone + Send + Sync + 'static> tide::Middleware<State> for CorsMiddleware {13
async fn handle(&self, req: tide::Request<State>, next: tide::Next<'_, State>) -> tide::Result {14
let mut res = next.run(req).await;15
res.insert_header("Access-Control-Allow-Origin", &self.origin);16
res.insert_header("Access-Control-Allow-Headers", "*");17
res.insert_header("Access-Control-Allow-Methods", "*");18
Ok(res)19
}20
}