Warp CORS error


I am having some issue with the CORS using warp

I have an API and i try to determine which method i am allowed to use.

My api is like:

let login = warp::path("login")
        .and_then(handlers::authentication::login_user); // login

let routes = register
        .with(warp::cors().allow_any_origin().allow_methods(vec!["OPTIONS", "GET", "POST", "DELETE", "PUT"]));

My code compile well, but when i:

curl -X OPTIONS '' -v

I get an error telling me the method is not allowed !!

The issue is that my browser sends an OPTIONS request before the POST request used to login.

The OPTIONS request get a 403 reply followed by a POST request that is blocked !!

Is there any missuse with the cors features?

What happens if you switch the order of the with(warp::cors()...) and recover(...)? I think your error isn't getting the CORS headers because it's being created after the CORS filter. I've had this same problem before.

Found the solution.

Solved here: https://github.com/seanmonstar/warp/issues/271

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.