use std::convert::Infallible;
use std::{include_str};
use std::net::SocketAddr;
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
use sailfish::TemplateOnce;
#[derive(TemplateOnce)]
#[template(path = "index.html")]
struct IndexTemplate {
pico: &'static str,
}
const PICO_CSS: &str = include_str!("../assets/pico.min.css");
async fn hello_world(_req: Request
) -> Result, Infallible> {
let body = IndexTemplate { pico: PICO_CSS }
.render_once()
.unwrap();
let resp: Response = Response::builder()
.status(200)
.header("content-type", "text/html")
.body(body.into())
.unwrap();
Ok(resp)
}
#[tokio::main]
async fn main() {
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(hello_world))
});
let server = Server::bind(&addr).serve(make_svc);
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
}