|
Hi, I want to create a dynamic App but have a complime error below: type mismatch resolving I enter the warp function, it's also return the App<
impl ServiceFactory<
ServiceRequest,
Response = ServiceResponse<B>,
Error = actix_web::Error,
Config = (),
InitError = (),
>,
>My code below: fn init_app<B>() -> App<
impl ServiceFactory<
ServiceRequest,
Response = ServiceResponse<B>,
Error = actix_web::Error,
Config = (),
InitError = (),
>,
> where B: MessageBody
{
let init_db_url = PROJECT_CONFIGS.db_url.as_ref();
let pg_conn = move || PgConnection::connect2(init_db_url);
let debug_app = App::new()
.data_factory(pg_conn)
.wrap(middleware::Compress::default())
.wrap(Cors::default().allow_any_origin());
let release_app = App::new()
.data_factory(pg_conn)
.wrap(middleware::Compress::default());
#[cfg(debug_assertions)]
if cfg!(debug_assertions) {
debug_app
} else {
release_app
}
}Thanks :) |
Answered by
robjtede
Jul 25, 2022
Replies: 2 comments 1 reply
This comment was marked as spam.
This comment was marked as spam.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dynamic apps are difficult for the same reason as dynamic anything is difficult in Rust.
The workaround for dynamic middleware is the
Conditionmiddleware wrapper.