Skip to content

Actix Web 4 - default_service SPA #2473

Discussion options

You must be logged in to vote

Here is a possible solution, not tested, only proof of concept that compiles:

use actix::fut::ok;
use actix_web::dev::ServiceRequest;
....

 .default_service(|r: ServiceRequest| {
      ok(crate::react_router::spa_index(r))
}),

And spa_index function:

pub (crate) fn spa_index(service_request: ServiceRequest) -> ServiceResponse
{
    let (req, _payload) = service_request.into_parts();

    let file_response = NamedFile::open("./static/index.html");

    ServiceResponse::new(req.clone(), file_response.respond_to(&req))
}

Hope it might help. I have much more elaborated spa_index, so only crafted the above as a theoretical exercise that compiles and looks like it might be working.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by StefanRupertsberger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants