This commit is contained in:
Untone 2023-10-18 13:00:14 +03:00
parent 0443ebd486
commit 8f236ab0dd

View File

@ -28,16 +28,12 @@ async fn connect_handler(
req: HttpRequest,
state: web::Data<AppState>,
) -> Result<HttpResponse, actix_web::Error> {
/*
let token = match req.headers().get("Authorization") {
Some(val) => val.to_str().unwrap_or("").split(" ").last().unwrap_or(""),
None => return Err(ErrorUnauthorized("Unauthorized")),
};
*/
let token = match req.match_info().get("token") {
Some(val) => val,
None => return Err(ErrorUnauthorized("Unauthorized")),
None => match req.match_info().get("token") {
Some(val) => val,
None => return Err(ErrorUnauthorized("Unauthorized")),
},
};
let listener_id = data::get_auth_id(&token).await.map_err(|e| {
@ -151,6 +147,7 @@ async fn main() -> std::io::Result<()> {
App::new()
.wrap(Logger::default())
.app_data(web::Data::new(state.clone()))
.route("/", web::get().to(connect_handler))
.route("/{token}", web::get().to(connect_handler))
})
.bind("0.0.0.0:8080")?