kochab/examples/serve_dir.rs

28 lines
685 B
Rust
Raw Normal View History

2020-10-31 19:53:03 +00:00
use anyhow::*;
2020-11-19 07:54:45 +00:00
use futures_core::future::BoxFuture;
use futures_util::FutureExt;
2020-11-14 02:56:50 +00:00
use log::LevelFilter;
2020-10-31 19:53:03 +00:00
use northstar::{Server, Request, Response, GEMINI_PORT};
#[tokio::main]
async fn main() -> Result<()> {
2020-11-14 02:56:50 +00:00
env_logger::builder()
.filter_module("northstar", LevelFilter::Debug)
.init();
2020-10-31 19:53:03 +00:00
Server::bind(("localhost", GEMINI_PORT))
.add_route("/", handle_request)
.serve()
2020-10-31 19:53:03 +00:00
.await
}
fn handle_request(request: Request) -> BoxFuture<'static, Result<Response>> {
async move {
let path = request.path_segments();
let response = northstar::util::serve_dir("public", &path).await?;
Ok(response)
}
.boxed()
}