Fix compilation errors from updating axum
This commit is contained in:
parent
66c66f3f4f
commit
174b23da1d
@ -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}"),
|
||||||
|
@ -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")))]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user