rebuilt to use message router.

This commit is contained in:
2024-11-06 21:05:52 -05:00
parent d4ce2ab03b
commit 52b6506088
9 changed files with 640 additions and 209 deletions

View File

@ -33,8 +33,7 @@ mod http_session {
async fn main() {
let args = Args::parse();
let addr = format!("{}:{}", args.address, args.port);
let nodes = args.node;
let state = MoreThanText::new(nodes);
let state = MoreThanText::new();
let app = Router::new().route("/", get(handler)).with_state(state);
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
@ -43,12 +42,11 @@ async fn main() {
}
async fn handler(jar: CookieJar, mut state: State<MoreThanText>) -> impl IntoResponse {
let sid: Option<String>;
let mut cookies = jar.clone();
match jar.get(SESSION_KEY) {
Some(cookie) => sid = Some(cookie.value().to_string()),
None => sid = None,
}
let sid = match jar.get(SESSION_KEY) {
Some(cookie) => Some(cookie.value().to_string()),
None => None,
};
state.open_session(sid.clone());
if !sid.is_some_and(|x| x == state.get_id()) {
let cookie = Cookie::build((SESSION_KEY, state.get_id()));