use std::future::Future;
use std::io;
use std::net::SocketAddr;
use axum::http::StatusCode;
use axum::response::IntoResponse;
pub fn start_server(
bind_addr: SocketAddr,
) -> Result<(String, impl Future<Output = Result<(), anyhow::Error>>), anyhow::Error> {
#[cfg(feature = "embed")]
let static_service = axum::routing::get(crate::embedded_client::client);
#[cfg(not(feature = "embed"))]
let static_service = axum::routing::get_service(tower_http::services::ServeDir::new(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../all-is-cubes-wasm/dist/"
)))
.handle_error(handle_error);
let app = axum::Router::new().route("/*path", static_service);
let server = axum::Server::bind(&bind_addr).serve(app.into_make_service());
let url = format!("http://{}/", server.local_addr());
Ok((url, async move { Ok(server.await?) }))
}
#[allow(dead_code)] async fn handle_error(_err: io::Error) -> impl IntoResponse {
(
StatusCode::INTERNAL_SERVER_ERROR,
"An internal error occurred.",
)
}