Refined docs and stuff
Docs link to each other and are generally better
This commit is contained in:
@@ -25,11 +25,12 @@ use crate::env::Env;
|
||||
/// Shared application state passed to all route handlers.
|
||||
///
|
||||
/// Contains the database connection pool and environment configuration.
|
||||
/// This is wrapped in Arc for thread-safe sharing across async tasks.
|
||||
/// This is wrapped in Arc for thread-safe sharing across async tasks and cloned into each route
|
||||
/// via `with_state`.
|
||||
///
|
||||
/// # Fields
|
||||
/// - `db`: PostgreSQL connection pool for database access
|
||||
/// - `env`: Configuration loaded from environment variables
|
||||
/// - `db`: PostgreSQL connection pool for database access (via `sqlx::PgPool`)
|
||||
/// - `env`: [`Env`] configuration loaded from environment variables
|
||||
pub struct AppState {
|
||||
db: PgPool,
|
||||
env: Env,
|
||||
@@ -39,15 +40,19 @@ pub struct AppState {
|
||||
///
|
||||
/// Initializes the server by:
|
||||
/// 1. Loading environment variables from `.env` file
|
||||
/// 2. Establishing database connection pool
|
||||
/// 2. Establishing database connection pool to PostgreSQL
|
||||
/// 3. Configuring CORS policy for cross-origin requests
|
||||
/// 4. Starting HTTP server on port 8001
|
||||
/// 4. Creating the router with [`create_router`] containing all endpoints
|
||||
/// 5. Starting HTTP server on port 8001
|
||||
///
|
||||
/// # Server Configuration
|
||||
/// - Binds to `0.0.0.0:8001` (all network interfaces)
|
||||
/// - Allows: GET, POST, PATCH, DELETE methods
|
||||
/// - Allows credentials and custom headers
|
||||
/// - CORS origin configured from environment
|
||||
/// - CORS origin configured from [`Env`]
|
||||
///
|
||||
/// # State Setup
|
||||
/// Creates shared [`AppState`] wrapped in `Arc` and passes to all routes
|
||||
///
|
||||
/// # Panics
|
||||
/// - If environment loading fails
|
||||
@@ -85,6 +90,7 @@ async fn main() {
|
||||
.layer(cors);
|
||||
|
||||
// Start listening for incoming connections
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8001").await.unwrap();
|
||||
let uri = format!("0.0.0.0:{}", env.backend_port);
|
||||
let listener = tokio::net::TcpListener::bind(&uri).await.unwrap();
|
||||
let _ = axum::serve(listener, app).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user