so://phie

verbal

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]

1pub struct CorsMiddleware {

2 origin: String,

3}

4

5impl CorsMiddleware {

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

7 Self { origin: origin.into() }

8 }

9}

10

11#[tide::utils::async_trait]

12impl<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}