Fix compilation errors from updating axum

This commit is contained in:
Ethan Girouard 2024-03-31 12:05:54 -04:00
parent 66c66f3f4f
commit 174b23da1d
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146
2 changed files with 6 additions and 8 deletions

View File

@ -2,7 +2,7 @@ use cfg_if::cfg_if;
cfg_if! { if #[cfg(feature = "ssr")] { cfg_if! { if #[cfg(feature = "ssr")] {
use axum::{ use axum::{
body::{boxed, Body, BoxBody}, body::Body,
extract::State, extract::State,
response::IntoResponse, response::IntoResponse,
http::{Request, Response, StatusCode, Uri}, http::{Request, Response, StatusCode, Uri},
@ -20,17 +20,17 @@ cfg_if! { if #[cfg(feature = "ssr")] {
if res.status() == StatusCode::OK { if res.status() == StatusCode::OK {
res.into_response() res.into_response()
} else { } else {
let handler = leptos_axum::render_app_to_stream(options.to_owned(), move || view!{<App/>}); let handler = leptos_axum::render_app_to_stream(options.to_owned(), App);
handler(req).await.into_response() handler(req).await.into_response()
} }
} }
async fn get_static_file(uri: Uri, root: &str) -> Result<Response<BoxBody>, (StatusCode, String)> { async fn get_static_file(uri: Uri, root: &str) -> Result<Response<Body>, (StatusCode, String)> {
let req = Request::builder().uri(uri.clone()).body(Body::empty()).unwrap(); let req = Request::builder().uri(uri.clone()).body(Body::empty()).unwrap();
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot` // `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
// This path is relative to the cargo root // This path is relative to the cargo root
match ServeDir::new(root).oneshot(req).await { match ServeDir::new(root).oneshot(req).await {
Ok(res) => Ok(res.map(boxed)), Ok(res) => Ok(res.into_response()),
Err(err) => Err(( Err(err) => Err((
StatusCode::INTERNAL_SERVER_ERROR, StatusCode::INTERNAL_SERVER_ERROR,
format!("Something went wrong: {err}"), format!("Something went wrong: {err}"),

View File

@ -42,10 +42,8 @@ async fn main() {
println!("listening on http://{}", &addr); println!("listening on http://{}", &addr);
axum::Server::bind(&addr) let listener = tokio::net::TcpListener::bind(&addr).await.expect(&format!("Could not bind to {}", &addr));
.serve(app.into_make_service()) axum::serve(listener, app.into_make_service()).await.expect("Server failed");
.await
.unwrap();
} }
#[cfg(not(any(feature = "ssr", feature = "csr")))] #[cfg(not(any(feature = "ssr", feature = "csr")))]