use actix_web::{get, web, App, HttpResponse, HttpServer, Responder, http::header::ContentType}; use macroblog::blog::{render_index_page, render_post_page}; use std::{env}; #[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) -> 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<()> { let port = env::var("PORT").unwrap_or("3000".into()).parse::().unwrap_or(3000); HttpServer::new(|| { App::new() .service(index) .service(posts) }) .bind(("0.0.0.0", port))? .run() .await }