Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actix-cors v0.5.4 not support actix-web v4.0.0-beta.1 version , but in actix-web v3.3.2 is fine #153

Closed
daviscai opened this issue Jan 31, 2021 · 1 comment

Comments

@daviscai
Copy link

daviscai commented Jan 31, 2021

Current Behavior

code :

use actix_cors::Cors;
use actix_web::{get, http, web, App, HttpRequest, HttpResponse, HttpServer};

#[get("/index.html")]
async fn index(req: HttpRequest) -> &'static str {
    "<p>Hello World!</p>"
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        let cors = Cors::default()
              .allowed_origin("https://www.rust-lang.org/")
              .allowed_origin_fn(|origin, _req_head| {
                  origin.as_bytes().ends_with(b".rust-lang.org")
              })
              .allowed_methods(vec!["GET", "POST"])
              .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
              .allowed_header(http::header::CONTENT_TYPE)
              .max_age(3600);

        App::new()
            .wrap(cors)
            .service(index)
    })
    .bind(("127.0.0.1", 8082))?
    .run()
    .await;

    Ok(())
}

cargo run :

warning: unused imports: `HttpResponse`, `web`
 --> src/main.rs:2:28
  |
2 | use actix_web::{get, http, web, App, HttpRequest, HttpResponse, HttpServer};
  |                            ^^^                    ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0277]: the trait bound `Cors: Transform<actix_web::app_service::AppRouting, ServiceRequest>` is not satisfied
  --> src/main.rs:23:19
   |
23 |             .wrap(cors)
   |                   ^^^^ the trait `Transform<actix_web::app_service::AppRouting, ServiceRequest>` is not implemented for `Cors`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_cors`

Your Environment

  • rustc -V
    rustc 1.49.0 (e1884a8e3 2020-12-29)

  • Actix-* crate(s) Version:

[dependencies]
actix-web = { version = "4.0.0-beta.1", features = ["openssl"] }
toml = "0.5.8"
actix-service = "2.0.0-beta.3"
actix-cors = "0.5.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
json = "0.12.4"
@robjtede
Copy link
Member

#144
#147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants