chyabrung-cli 0.2.0

The `chy` command line tool for Chyabrung: scaffolding, dev server with hot reload, builds, generators, migrations and one-command deploys
//! # Routes: every URL of the app, in one place
//!
//! Start here. Each line connects an HTTP method and a path to a handler in
//! `src/controllers/`. Groups share a URL prefix and middleware.
//!
//! - `.get("/me", auth_controller::me)` connects one URL to one function.
//! - `.mount(PostController)` adds every route of a `#[controller]` at once.
//! - `:id` in a path is a parameter, read in the handler with `Path(id)`.
//! - Run `cargo run` or `chy dev` and open http://127.0.0.1:2007/docs for the API docs.

use crate::controllers::post_controller::PostController;
use crate::controllers::{auth_controller, realtime_controller, stats_controller, upload_controller};
use chyabrung::prelude::*;
use std::time::Duration;

/// Add all routes to the app.
pub fn register(app: App) -> App {
    app.get("/", welcome) // the welcome page: replace it with your own handler
        .get("/ws", realtime_controller::socket)
        .group("/api", |r| {
            r.group("/auth", |r| {
                r.middleware(rate_limit(20, Duration::from_secs(60))) // slow down password guessing
                    .post("/register", auth_controller::register)
                    .post("/login", auth_controller::login)
            })
            .get("/me", auth_controller::me)
            .mount(PostController) // GET/POST /api/posts, GET/PUT/DELETE /api/posts/:id
            .get("/stats", stats_controller::index)
            .post("/upload", upload_controller::store)
            .get("/events", realtime_controller::events)
            // chy:resources (`chy make:resource` mounts new controllers above this line)
        })
}