diff --git a/src/main.rs b/src/main.rs index 43c279a..db430c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use actix_web::{web, App, HttpResponse, HttpServer, web::Bytes}; +use actix_web::{HttpRequest, web, App, HttpResponse, HttpServer, web::Bytes}; use actix_web::middleware::Logger; use redis::{Client, AsyncCommands}; use std::collections::HashMap; @@ -18,9 +18,13 @@ struct AppState { } async fn connect_handler( - token: web::Path, + req: HttpRequest, state: web::Data, ) -> Result { + let token = match req.headers().get("Authorization") { + Some(val) => val.to_str().unwrap_or(""), + None => return Err(ErrorUnauthorized("Unauthorized")), + }; let listener_id = data::get_auth_id(&token).await.map_err(|e| { eprintln!("TOKEN check failed: {}", e); ErrorUnauthorized("Unauthorized") @@ -86,9 +90,13 @@ async fn connect_handler( async fn disconnect_handler( - token: web::Path, + req: HttpRequest, state: web::Data, ) -> Result { + let token = match req.headers().get("Authorization") { + Some(val) => val.to_str().unwrap_or(""), + None => return Err(ErrorUnauthorized("Unauthorized")), + }; let listener_id = data::get_auth_id(&token).await.map_err(|e| { eprintln!("TOKEN check failed: {}", e); ErrorUnauthorized("Unauthorized") @@ -116,9 +124,8 @@ async fn main() -> std::io::Result<()> { tasks: tasks.clone(), redis: client.clone(), }; - println!("Redis client initialized"); + println!("Starting..."); HttpServer::new(move || { - println!("Webserver initialized"); App::new() .wrap(Logger::default()) .app_data(web::Data::new(state.clone()))