aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..0c3565b
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,45 @@
+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<Body>) -> Result<Response<Body>, Infallible> {
+ let body = IndexTemplate { pico: PICO_CSS }
+ .render_once()
+ .unwrap();
+
+ let resp: Response<Body> = 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);
+ }
+}