2021-06-06 21:53:22 +02:00
|
|
|
use http::StatusCode;
|
|
|
|
use hyper::Server;
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
use tower::make::Shared;
|
|
|
|
use tower_http::{services::ServeDir, trace::TraceLayer};
|
2021-06-08 12:43:16 +02:00
|
|
|
use tower_web::{prelude::*, service::ServiceExt};
|
2021-06-06 21:53:22 +02:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
let app = tower_web::routing::nest(
|
|
|
|
"/static",
|
2021-06-07 15:45:19 +02:00
|
|
|
tower_web::service::get(ServeDir::new(".").handle_error(|error: std::io::Error| {
|
2021-06-06 21:53:22 +02:00
|
|
|
(
|
|
|
|
StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
|
format!("Unhandled interal error: {}", error),
|
|
|
|
)
|
2021-06-07 15:45:19 +02:00
|
|
|
})),
|
2021-06-06 21:53:22 +02:00
|
|
|
)
|
|
|
|
.layer(TraceLayer::new_for_http());
|
|
|
|
|
|
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
|
|
tracing::debug!("listening on {}", addr);
|
|
|
|
let server = Server::bind(&addr).serve(Shared::new(app));
|
|
|
|
server.await.unwrap();
|
|
|
|
}
|