aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2022-05-05 23:15:41 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2022-05-05 23:15:41 +0200
commite7c5dc01cf3bf382c82dd6984808bd3ca21d33a5 (patch)
treeb1f1d6fd9e8bc4814f8c8f541456519660bbe2b1 /src
downloadmacroblog.rs-e7c5dc01cf3bf382c82dd6984808bd3ca21d33a5.tar.gz
macroblog.rs-e7c5dc01cf3bf382c82dd6984808bd3ca21d33a5.tar.bz2
macroblog.rs-e7c5dc01cf3bf382c82dd6984808bd3ca21d33a5.zip
Initial commit
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);
+ }
+}