so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: 33a39d0cf385f55eb748f24735d79294d4e10db0 (651 bytes)[doc][blame][raw]

1pub struct Cors {

2 origin: String,

3}

4

5impl Cors {

6 #[must_use]

7 pub fn new(origin: &str) -> Self {

8 Self {

9 origin: origin.into(),

10 }

11 }

12}

13

14#[tide::utils::async_trait]

15impl<State: Clone + Send + Sync + 'static> tide::Middleware<State> for Cors {

16 async fn handle(&self, req: tide::Request<State>, next: tide::Next<'_, State>) -> tide::Result {

17 let mut res = next.run(req).await;

18 res.insert_header("Access-Control-Allow-Origin", &self.origin);

19 res.insert_header("Access-Control-Allow-Headers", "*");

20 res.insert_header("Access-Control-Allow-Methods", "*");

21 Ok(res)

22 }

23}