init
This commit is contained in:
53
libertas_api/src/main.rs
Normal file
53
libertas_api/src/main.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use axum::{
|
||||
Router,
|
||||
routing::{get, post},
|
||||
};
|
||||
|
||||
use crate::handlers::{
|
||||
album_handlers, auth_handlers,
|
||||
media_handlers::{self},
|
||||
};
|
||||
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
pub mod factory;
|
||||
pub mod handlers;
|
||||
pub mod middleware;
|
||||
pub mod repositories;
|
||||
pub mod security;
|
||||
pub mod services;
|
||||
pub mod state;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let config = config::load_config()?;
|
||||
let addr: SocketAddr = config.server_address.parse()?;
|
||||
|
||||
let app_state = factory::build_app_state(config).await?;
|
||||
|
||||
let auth_routes = Router::new()
|
||||
.route("/register", post(auth_handlers::register))
|
||||
.route("/login", post(auth_handlers::login));
|
||||
|
||||
let user_routes = Router::new().route("/me", get(auth_handlers::get_me));
|
||||
let media_routes = media_handlers::media_routes();
|
||||
let album_routes = album_handlers::album_routes();
|
||||
|
||||
let app = Router::new()
|
||||
.route("/api/v1/health", get(|| async { "OK" }))
|
||||
.nest("/api/v1/auth", auth_routes)
|
||||
.nest("/api/v1/users", user_routes)
|
||||
.nest("/api/v1/media", media_routes)
|
||||
.nest("/api/v1/albums", album_routes)
|
||||
.with_state(app_state);
|
||||
|
||||
println!("Starting server at http://{}", addr);
|
||||
|
||||
let listner = tokio::net::TcpListener::bind(addr).await?;
|
||||
|
||||
axum::serve(listner, app.into_make_service()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user