macroblog.rs @ 519b9904d892f9e3e54920377c58f62fefbb7383

 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    let port = env::var("PORT").unwrap_or("3000".into()).parse::<u16>().unwrap_or(3000);
27    HttpServer::new(|| {
28        App::new()
29            .service(index)
30            .service(posts)
31    })
32    .bind(("0.0.0.0", port))?
33    .run()
34    .await
35}