build: add api server config loader
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
mod app;
|
||||
mod config;
|
||||
mod state;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
use crate::{app::build_router, state::AppState};
|
||||
use crate::{app::build_router, config::AppConfig, state::AppState};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
// 当前阶段先用固定地址启动最小骨架,后续再切到统一配置加载。
|
||||
let bind_address = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||
// 统一先从配置对象读取监听地址,避免后续把环境变量读取散落到入口和路由层。
|
||||
let config = AppConfig::from_env();
|
||||
let bind_address = config.bind_socket_addr();
|
||||
let listener = TcpListener::bind(bind_address).await?;
|
||||
|
||||
let state = AppState::new();
|
||||
let state = AppState::new(config);
|
||||
let router = build_router(state);
|
||||
|
||||
axum::serve(listener, router).await
|
||||
|
||||
Reference in New Issue
Block a user