Skip to content

Commit

Permalink
fix: remove unnecessary default features on axum in server_fns to…
Browse files Browse the repository at this point in the history
… support running Axum in a WASM environment (#2270)
  • Loading branch information
sjud authored Feb 7, 2024
1 parent a903e19 commit 1b55227
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion integrations/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ axum = { version = "0.7", default-features = false, features = [
futures = "0.3"
http-body-util = "0.1"
leptos = { workspace = true, features = ["ssr"] }
server_fn = { workspace = true, features = ["axum"] }
server_fn = { workspace = true, features = ["axum-no-default"] }
leptos_macro = { workspace = true, features = ["axum"] }
leptos_meta = { workspace = true, features = ["ssr"] }
leptos_router = { workspace = true, features = ["ssr"] }
Expand Down
8 changes: 6 additions & 2 deletions server_fn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ once_cell = "1"
actix-web = { version = "4", optional = true }

# axum
axum = { version = "0.7", optional = true, features = ["multipart"] }
axum = { version = "0.7", optional = true, default-features = false, features = ["multipart"] }
tower = { version = "0.4", optional = true }
tower-layer = { version = "0.3", optional = true }

Expand Down Expand Up @@ -75,14 +75,18 @@ url = "2"
default = ["json", "cbor"]
form-redirects = []
actix = ["ssr", "dep:actix-web", "dep:send_wrapper"]
axum = [
axum-no-default = [
"ssr",
"dep:axum",
"dep:hyper",
"dep:http-body-util",
"dep:tower",
"dep:tower-layer",
]
axum = [
"axum/default",
"axum-no-default",
]
browser = [
"dep:gloo-net",
"dep:js-sys",
Expand Down
4 changes: 2 additions & 2 deletions server_fn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub mod response;
#[cfg(feature = "actix")]
#[doc(hidden)]
pub use ::actix_web as actix_export;
#[cfg(feature = "axum")]
#[cfg(feature = "axum-no-default")]
#[doc(hidden)]
pub use ::axum as axum_export;
use client::Client;
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<Req: 'static, Res: 'static> inventory::Collect
}

/// Axum integration.
#[cfg(feature = "axum")]
#[cfg(feature = "axum-no-default")]
pub mod axum {
use crate::{
middleware::{BoxedService, Service},
Expand Down
2 changes: 1 addition & 1 deletion server_fn/src/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait Service<Request, Response> {
) -> Pin<Box<dyn Future<Output = Response> + Send>>;
}

#[cfg(feature = "axum")]
#[cfg(feature = "axum-no-default")]
mod axum {
use super::{BoxedService, Service};
use crate::{response::Res, ServerFnError};
Expand Down
2 changes: 1 addition & 1 deletion server_fn/src/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{borrow::Cow, future::Future};
#[cfg(feature = "actix")]
pub mod actix;
/// Request types for Axum.
#[cfg(feature = "axum")]
#[cfg(feature = "axum-no-default")]
pub mod axum;
/// Request types for the browser.
#[cfg(feature = "browser")]
Expand Down
2 changes: 1 addition & 1 deletion server_fn/src/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod actix;
#[cfg(feature = "browser")]
pub mod browser;
/// Response types for Axum.
#[cfg(feature = "axum")]
#[cfg(feature = "axum-no-default")]
pub mod http;
/// Response types for [`reqwest`].
#[cfg(feature = "reqwest")]
Expand Down
4 changes: 2 additions & 2 deletions server_fn_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ pub fn server_macro_impl(
quote! {
#server_fn_path::request::BrowserMockReq
}
} else if cfg!(feature = "axum") {
} else if cfg!(feature = "axum-no-default") {
quote! {
#server_fn_path::axum_export::http::Request<#server_fn_path::axum_export::body::Body>
}
Expand All @@ -458,7 +458,7 @@ pub fn server_macro_impl(
quote! {
#server_fn_path::response::BrowserMockRes
}
} else if cfg!(feature = "axum") {
} else if cfg!(feature = "axum-no-default") {
quote! {
#server_fn_path::axum_export::http::Response<#server_fn_path::axum_export::body::Body>
}
Expand Down

0 comments on commit 1b55227

Please sign in to comment.