aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/actix.rs34
-rw-r--r--src/bin/hyper.rs (renamed from src/main.rs)1
2 files changed, 34 insertions, 1 deletions
diff --git a/src/bin/actix.rs b/src/bin/actix.rs
new file mode 100644
index 0000000..dd03ece
--- /dev/null
+++ b/src/bin/actix.rs
@@ -0,0 +1,34 @@
+use actix_web::{get, web, App, HttpResponse, HttpServer, Responder, http::header::ContentType};
+use macroblog::blog::{render_index_page, render_post_page};
+
+#[get("/")]
+async fn index() -> impl Responder {
+ let body = render_index_page();
+
+ HttpResponse::Ok()
+ .content_type(ContentType::html())
+ .body(body)
+}
+
+
+#[get("/posts/{name}")]
+async fn posts(name: web::Path<String>) -> impl Responder {
+ let body = render_post_page(&name);
+
+ HttpResponse::Ok()
+ .content_type(ContentType::html())
+ .body(body)
+}
+
+
+#[actix_web::main]
+async fn main() -> std::io::Result<()> {
+ HttpServer::new(|| {
+ App::new()
+ .service(index)
+ .service(posts)
+ })
+ .bind(("0.0.0.0", 3000))?
+ .run()
+ .await
+}
diff --git a/src/main.rs b/src/bin/hyper.rs
index ed34713..3f23f18 100644
--- a/src/main.rs
+++ b/src/bin/hyper.rs
@@ -1,4 +1,3 @@
-
use std::convert::Infallible;
use std::{env};
use std::net::SocketAddr;