PersonalWebApplication/Server/src/state.rs
cc 58284f3fe0 feat: add login/auth system + blog page with rainbow design
- 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>
2026-06-18 00:00:38 +08:00

29 lines
733 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! 共享应用状态。
//!
//! 采样任务(写)与 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()),
}
}
}