arc-web-cli 0.3.0

Create self-contained Arc applications
1
2
3
4
5
6
7
8
9
10
11
12
13
use actix_web::{get, HttpResponse, Responder};
use tera::{Context, Tera};

#[get("/")]
pub async fn home() -> impl Responder {
    let template = include_str!("../resources/views/home.html");
    let mut context = Context::new();
    context.insert("app_name", env!("CARGO_PKG_NAME"));
    match Tera::one_off(template, &context, true) {
        Ok(html) => HttpResponse::Ok().content_type("text/html; charset=utf-8").body(html),
        Err(error) => HttpResponse::InternalServerError().body(format!("template error: {error}")),
    }
}