- Client: auth API wrapper (api/auth.ts) + useAuth hook with localStorage persistence - Client: LoginPage/LoginForm with remember-me and loading states - Client: BlogPage with hero section, rainbow spotlight cursor effect, post list - Client: CSS rainbow gradient utilities for text/borders/backgrounds - Server: POST /api/web/login with username/password verification + token - Server: CORS extended to POST + Content-Type header - Server: auth.rs token issuer, serde dependency for JSON - Chore: gitignore Server/.vite Co-Authored-By: Claude <noreply@anthropic.com>
29 lines
733 B
Rust
29 lines
733 B
Rust
//! 共享应用状态。
|
||
//!
|
||
//! 采样任务(写)与 HTTP handler(读)通过一个被 `RwLock` 保护的
|
||
//! `Stats` 快照通信。`AppState` 可廉价 `clone`(内部是 `Arc`)。
|
||
|
||
use std::sync::Arc;
|
||
|
||
use tokio::sync::RwLock;
|
||
|
||
use crate::auth::UserStore;
|
||
use crate::monitor::Stats;
|
||
|
||
#[derive(Clone)]
|
||
pub struct AppState {
|
||
/// 最新一次采样快照。
|
||
pub snapshot: Arc<RwLock<Stats>>,
|
||
/// 用户表:启动时构建一次、之后只读,故无需锁,用 `Arc` 共享即可。
|
||
pub users: Arc<UserStore>,
|
||
}
|
||
|
||
impl AppState {
|
||
pub fn new() -> Self {
|
||
Self {
|
||
snapshot: Arc::new(RwLock::new(Stats::default())),
|
||
users: Arc::new(UserStore::seed()),
|
||
}
|
||
}
|
||
}
|