feat(server): integrate AppState, ModuleRegistry, health check, and graceful shutdown
- Add AppState with DB, Config, EventBus, ModuleRegistry via Axum State - ModuleRegistry now uses Arc for Clone support, builder-pattern register() - Add /api/v1/health endpoint returning status, version, registered modules - Add graceful shutdown on CTRL+C / SIGTERM - erp-common utils: ID generation, timestamp helpers, code generator with tests - Config structs now derive Clone for state sharing - Update wiki to reflect Phase 1 completion
This commit is contained in:
23
crates/erp-server/src/state.rs
Normal file
23
crates/erp-server/src/state.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use axum::extract::FromRef;
|
||||
use sea_orm::DatabaseConnection;
|
||||
|
||||
use crate::config::AppConfig;
|
||||
use erp_core::events::EventBus;
|
||||
use erp_core::module::ModuleRegistry;
|
||||
|
||||
/// Axum 共享应用状态
|
||||
/// 所有 handler 通过 State<AppState> 获取数据库连接、配置等
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub db: DatabaseConnection,
|
||||
pub config: AppConfig,
|
||||
pub event_bus: EventBus,
|
||||
pub module_registry: ModuleRegistry,
|
||||
}
|
||||
|
||||
/// 允许 handler 直接提取子字段
|
||||
impl FromRef<AppState> for DatabaseConnection {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
state.db.clone()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user