PersonalWebApplication/Server/src/main.rs

31 lines
829 B
Rust
Raw Normal View History

//! InternetProject 后端入口。
//!
//! 启动一个后台采样任务持续刷新系统指标,并对外提供 HTTP 接口:
//! - `GET /api/web/stats` 给 React 前端(挂 CORS
//! - `GET /api/client/health` 给未来 .NET 客户端(不挂 CORS
mod auth;
mod monitor;
mod routes;
mod state;
use state::AppState;
#[tokio::main]
async fn main() {
let state = AppState::new();
// 后台每秒采样系统指标,写入共享快照。
tokio::spawn(monitor::run_sampler(state.clone()));
let app = routes::build_router(state);
let addr = "0.0.0.0:8080";
let listener = tokio::net::TcpListener::bind(addr)
.await
.expect("无法绑定 0.0.0.0:8080");
println!("backend listening on http://{addr}");
axum::serve(listener, app).await.expect("server error");
}