-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
support #[middleware] macro on server functions for actix #2436
Labels
Comments
sify21
changed the title
support actix middleware for server functions
support #[middleware] macro on server functions for actix
Mar 17, 2024
I spent a while trying to implement this before 0.6, and kept running into "X does not implement Y" trait errors that I wasn't able to figure out, not being familiar at all with Actix middleware. Very open to any changes to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I want to implement server-side auth with actix framework, which is normally done by middlewares. Currently Leptos supports defining axum middlewares, like in the following example:
leptos/examples/server_fns_axum/src/app.rs
Lines 249 to 257 in 97fd8ff
leptos/examples/server_fns_axum/src/middleware.rs
Lines 9 to 28 in 97fd8ff
I tried to implement the necessary traits in
server_fn/src/middleware/mod.rs
for actix's middleware to work in the same way, but found it's not possible.The reason is that actix's middleware, which implements
actix_service::Transform
trait, is actually a "service-generating factory", and it generates the wrapping Service (or the Transform component) asynchronously. However, Leptos'sLayer
trait works in synchronous way.Describe the solution you'd like
Be able to use
#[middleware]
macros for actix's server functions, just like middlewares for axum's server functionsDescribe alternatives you've considered
I can call
handle_server_fns()
method fromleptos-actix
, and register the returnedRoute
manually. But this has two drawbacks:leptos-actix
already did this:leptos/integrations/actix/src/lib.rs
Lines 1275 to 1280 in 97fd8ff
Additional context
Here is how I tried to implement it in my fork
sify21@4381aad
The text was updated successfully, but these errors were encountered: