split backend into bin and lib

This commit is contained in:
2025-07-14 03:11:27 +02:00
parent af2829317f
commit 85bc353a5a
20 changed files with 38 additions and 32 deletions

View File

@@ -3,6 +3,14 @@ name = "warren"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
[lib]
name = "warren"
path = "src/lib/lib.rs"
[[bin]]
name = "warren_backend"
path = "src/bin/backend/main.rs"
[dependencies] [dependencies]
axum = { version = "0.8.4", features = ["multipart", "query"] } axum = { version = "0.8.4", features = ["multipart", "query"] }
dotenv = "0.15.0" dotenv = "0.15.0"

View File

@@ -0,0 +1,19 @@
use warren::{server, Result};
#[tokio::main]
async fn main() -> Result<()> {
dotenv::dotenv().ok();
env_logger::builder()
.format_target(false)
.filter_level(log::LevelFilter::Info)
.parse_env("LOG_LEVEL")
.parse_default_env()
.init();
let pool = warren::db::get_postgres_pool().await?;
server::start(pool).await?;
Ok(())
}

View File

@@ -1,5 +1,3 @@
use std::error::Error;
use axum::{ use axum::{
body::Body, body::Body,
extract::multipart::MultipartError, extract::multipart::MultipartError,

10
backend/src/lib/lib.rs Normal file
View File

@@ -0,0 +1,10 @@
use error::AppError;
pub mod api;
pub mod db;
pub mod error;
pub mod fs;
pub mod server;
pub mod warrens;
pub type Result<T> = std::result::Result<T, AppError>;

View File

@@ -15,7 +15,7 @@ use crate::{
pub type Router = axum::Router<AppState>; pub type Router = axum::Router<AppState>;
pub(super) async fn start(pool: Pool<Postgres>) -> Result<()> { pub async fn start(pool: Pool<Postgres>) -> Result<()> {
let cors_origin = env::var("CORS_ALLOW_ORIGIN").unwrap_or("*".to_string()); let cors_origin = env::var("CORS_ALLOW_ORIGIN").unwrap_or("*".to_string());
let serve_dir = std::env::var("SERVE_DIRECTORY")?; let serve_dir = std::env::var("SERVE_DIRECTORY")?;

View File

@@ -1,29 +0,0 @@
use db::get_postgres_pool;
use error::AppError;
pub mod api;
pub mod db;
pub mod error;
pub mod fs;
mod server;
pub mod warrens;
pub type Result<T> = std::result::Result<T, AppError>;
#[tokio::main]
async fn main() -> std::result::Result<(), AppError> {
dotenv::dotenv().ok();
env_logger::builder()
.format_target(false)
.filter_level(log::LevelFilter::Info)
.parse_env("LOG_LEVEL")
.parse_default_env()
.init();
let pool = get_postgres_pool().await?;
server::start(pool).await?;
Ok(())
}