AkurAI Build
Menu

Public repository / 01b0c3e49ec2c526bbda745999ffed8ebfa8b8ee

AkurAI-Drive / backend/src/main.rs

Latest change 6e3a0824f4ec4d2bea2524a20b4960c7ab9e2766 - backend: akurai-drive-api (OIDC RP + per-tenant S3 provisioning) by olibuijr

pub mod api;
pub mod auth;
pub mod config;
pub mod db;
pub mod idp;
pub mod pages;
pub mod session;
pub mod util;

use axum::{Json, Router, http::StatusCode, response::IntoResponse, routing::get};
use serde_json::json;

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::try_from_default_env()
                .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
        )
        .init();

    tracing::info!("akurai-drive-api starting up");

    // Trigger DB initialization (opens the connection, sets pragmas, creates tables).
    db::with_db(|_conn| {});

    let cfg = config::get();

    let app = Router::new()
        .route("/healthz", get(healthz))
        .route("/auth/login", get(auth::login))
        .route("/auth/callback", get(auth::callback))
        .route("/auth/logout", get(auth::logout))
        .route("/api/me", get(api::me))
        .route(
            "/api/storage",
            get(api::storage_list).post(api::storage_create),
        )
        .route("/app", get(pages::app))
        .fallback(not_found);

    tracing::info!("listening on {}", cfg.listen_addr);

    let listener = tokio::net::TcpListener::bind(&cfg.listen_addr)
        .await
        .expect("failed to bind listener");

    axum::serve(listener, app).await.expect("server error");
}

async fn healthz() -> impl IntoResponse {
    Json(json!({"ok": true, "service": "akurai-drive-api"}))
}

async fn not_found() -> impl IntoResponse {
    (StatusCode::NOT_FOUND, Json(json!({"error": "not found"})))
}