Why this error trying to conditionally wrap my actix-web app? #2846
Answered
by
asonix
frederikhors
asked this question in
Q&A
-
|
I'm trying to conditionally wrap my app with CORS, but I'm getting errors. use actix_cors::Cors;
use actix_web::{http::header, App, HttpServer};
use std::{net::SocketAddr, sync::Arc};
use common::config::Config;
pub async fn start(config: Arc<Config>) -> std::io::Result<()> {
let config_app = Arc::clone(&config);
let server = HttpServer::new(move || {
let mut app = App::new();
if config_app.cors.enabled {
app = app.wrap( // the error is here, read below
Cors::default()
.allowed_origin("http://localhost:8080")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.supports_credentials()
.max_age(3600),
)
}
app
});
let addr = SocketAddr::from(([127, 0, 0, 1], config.port));
server.bind(addr)?.run().await
}the error is: Why? |
Beta Was this translation helpful? Give feedback.
Answered by
asonix
Aug 22, 2022
Replies: 1 comment 4 replies
-
|
by applying |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
frederikhors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
by applying
.wrapto anAppyou change it's type