chyabrung-cli 0.2.5

The `chy` command line tool for Chyabrung: scaffolding, dev server with hot reload, builds, generators, migrations and one-command deploys
pub mod controllers;
pub mod mail;
pub mod middleware;
pub mod models;
pub mod requests;
pub mod responses;
pub mod routes;

use chyabrung::prelude::*;
use chyabrung::auth::has_role;
use chyabrung::maintenance::Maintenance;
use chyabrung::storage::Storage;
use std::time::Duration;

pub fn migrator() -> Result<Migrator> {
    Ok(chyabrung::db::migrations!())
}

pub fn app(db: Db, jwt: Jwt, cache: Cache, storage: Storage) -> App {
    let roles = Roles::new().role("admin", &["*"]).role("editor", &["posts.update"]).role("user", &[]);

    App::new()
        .state(db)
        .state(jwt.clone())
        .state(cache)
        .state(storage)
        .state(roles)
        .middleware(request_id())
        .middleware(logger())
        .middleware(secure_headers())
        .middleware(cors())
        .middleware(compression())
        .middleware(timeout(Duration::from_secs(30)))
        .middleware(authenticate().jwt(jwt))
        .maintenance(Maintenance::new().allow(has_role("admin")).except("/assets"))
        .static_files("/assets", "public")
        .static_files("/storage", "storage/public")
        .body_limit(10 * 1024 * 1024)
        .openapi(OpenApi::new("{{app_name}}", env!("CARGO_PKG_VERSION")))
        .routes(routes::routes)
}