monorepo/visions/server/src/main.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

use core::Core;
use std::path::PathBuf;
2024-12-27 19:29:07 +00:00
use asset_db::FsAssets;
use axum::{routing::{get, post}, Router, Json};
use database::DbConn;
mod asset_db;
mod core;
mod database;
2024-12-27 19:29:07 +00:00
mod filters;
mod handlers;
use handlers::{ healthcheck, check_password, AuthRequest};
mod types;
#[tokio::main]
pub async fn main() {
/*
2024-12-22 14:17:00 +00:00
pretty_env_logger::init();
2024-12-27 19:02:43 +00:00
let unauthenticated_endpoints = route_healthcheck().or(route_authenticate(core.clone()));
let authenticated_endpoints = route_image(core.clone());
*/
let conn = DbConn::new(Some("/home/savanni/game.db"));
let core = Core::new(FsAssets::new(PathBuf::from("/home/savanni/Pictures")), conn);
let app = Router::new().route(
"/api/v1/health",
get({
let core = core.clone();
move || healthcheck(core)
}),
).route(
"/api/v1/auth",
post({
let core = core.clone();
move |req: Json<AuthRequest>| handlers::check_password(core, req)
}),
2024-12-27 19:29:07 +00:00
);
let listener = tokio::net::TcpListener::bind("127.0.0.1:8001")
.await
.unwrap();
axum::serve(listener, app).await.unwrap();
}