Feature Request

With ServeDir::new(".").precompressed_gzip() one can serve precompressed files to the client. I am wondering how I can achieve the same with the SpaRouter.

See https://github.com/tokio-rs/axum/issues/66#issuecomment-970730249

let app: _ = Router::new()
    .merge(axum_extra::routing::SpaRouter::new("/dist", "src/static/dist"))
    .route("/api/userinfo", get(userinfo))
    .layer(TraceLayer::new_for_http())
    .layer(AddExtensionLayer::new(groups));

Motivation

How else could I serve precompressed files while also utilizing features of SpaRouter?

Proposal

Add precompressed methods as done with ServeDir?

0

If recommend just using ServeDir directly.

0

For future googlers my solution

let app: _ = Router::new()
    // .merge(axum_extra::routing::SpaRouter::new("/dist", "src/static/dist"))
    // Not perfect because all not-found paths are redirected to there
    .fallback(get_service(ServeFile::new("src/static/dist/index.html")).handle_error(handle_error)) 
    .nest("/dist", get_service(ServeDir::new("src/static/dist").precompressed_br()).handle_error(handle_error))
    .nest("/api/userinfo", get(userinfo))
    .layer(TraceLayer::new_for_http())
    .layer(AddExtensionLayer::new(groups));
0
© 2022 pullanswer.com - All rights reserved.