Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions backend/modules/api/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::idempotency::IdempotencyMiddleware;
use crate::players::{add_player, delete_player, find_player_by_id, update_player};
use crate::rate_limiter::RedisRateLimiter;
use crate::request_id::RequestIdMiddleware;
use crate::ws::{ws_route, LobbyState};
use crate::ws::{ws_route, LobbyState, ConnectionStateTracker};
use actix::Actor;
use actix_cors::Cors;
use actix_governor::{Governor, GovernorConfigBuilder};
Expand Down Expand Up @@ -163,6 +163,9 @@ pub async fn main() -> std::io::Result<()> {

// Create a shared LobbyState actor
let lobby = LobbyState::new().start();

// Create a shared ConnectionStateTracker actor with DB pool for game session management
let connection_tracker = ConnectionStateTracker::new(Some((*db_pool).clone())).start();

// Load AppConfig
let config = AppConfig::from_env();
Expand Down Expand Up @@ -191,6 +194,7 @@ pub async fn main() -> std::io::Result<()> {
let jwt_secret = jwt_secret.clone();
let matchmaking_service = matchmaking_service.clone();
let puzzle_service = puzzle_service.clone();
let connection_tracker = connection_tracker.clone();

// Configure CORS middleware with environment variables for flexibility
let cors = {
Expand Down Expand Up @@ -258,6 +262,7 @@ pub async fn main() -> std::io::Result<()> {
.app_data(web::Data::from(db_pool.clone()))
.app_data(web::Data::new(jwt_service.clone()))
.app_data(web::Data::new(lobby.clone()))
.app_data(web::Data::new(connection_tracker.clone()))
.app_data(web::Data::new(matchmaking_service.clone()))
.app_data(web::Data::new(puzzle_service.clone()))
.app_data(web::Data::new(metrics_collector.clone()))
Expand Down Expand Up @@ -422,4 +427,4 @@ pub async fn main() -> std::io::Result<()> {
});

server.await
}
}
Loading
Loading