macroblog.rs @ c434c45380fc6926a5525f97cc4df98a9b3cda94

 1use actix_web::{get, web, App, HttpResponse, HttpServer, Responder, http::header::ContentType};
 2use macroblog::blog::{render_index_page, render_post_page};
 3
 4#[get("/")]
 5async fn index() -> impl Responder {
 6    let body = render_index_page();
 7
 8    HttpResponse::Ok()
 9        .content_type(ContentType::html())
10        .body(body)
11}
12
13
14#[get("/posts/{name}")]
15async fn posts(name: web::Path<String>) -> impl Responder {
16    let body = render_post_page(&name);
17
18    HttpResponse::Ok()
19        .content_type(ContentType::html())
20        .body(body)
21}
22
23
24#[actix_web::main]
25async fn main() -> std::io::Result<()> {
26    HttpServer::new(|| {
27        App::new()
28            .service(index)
29            .service(posts)
30    })
31    .bind(("0.0.0.0", 3000))?
32    .run()
33    .await
34}