0

I want to use the crate rocket_cors for Rocket v0.5.0-rc.2 but it does not compile because "the trait bound 'Cors: Fairing' is not satisfied".

Here is my Cargo.toml:

# --snip--
[dependencies]
rocket = { version = "0.5.0-rc.2", features = [ "json" ] }
rocket_cors = { version = "0.5.2", default-features = false }
# --snip--

And here is my rocket() function:

fn rocket() -> _ {
    let cors = rocket_cors::CorsOptions {
        allowed_origins: AllowedOrigins::all(),
        allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]),
        allow_credentials: true,
        ..Default::default()
    }
    .to_cors()
    .unwrap();
    rocket::build()
        .attach(DbConnection::fairing())
        .attach(cors) // <- Here's the error: "the trait `Fairing` is not implemented for `Cors`"
        .mount("/", routes![get_tasks])
}

I won't have a problem if the solution is using another CORS crate either.

drpe
  • 51
  • 9

1 Answers1

1

I had the same issue and this solved it:

i decided not to use rocket_cors and implemented a the solution in this post

https://stackoverflow.com/a/75522665/21825956

e0x
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '23 at 11:36