63 lines
1.5 KiB
Rust
63 lines
1.5 KiB
Rust
use axum::serve;
|
|
use axum::Extension;
|
|
use axum::extract::{ws::{Message, WebSocket, WebSocketUpgrade}, State};
|
|
use jsonwebtoken::{DecodingKey, EncodingKey};
|
|
use tokio::net::TcpListener;
|
|
use tokio::sync::mpsc;
|
|
|
|
mod utils;
|
|
mod routes;
|
|
mod rooms;
|
|
mod chat;
|
|
mod inventory;
|
|
use r2d2::{Pool};
|
|
use r2d2_sqlite::SqliteConnectionManager;
|
|
use dashmap::DashMap;
|
|
use std::sync::Arc;
|
|
|
|
use crate::utils::db_pool::{HotelPool,AppState};
|
|
use routes::create_router;
|
|
use crate::utils::auth::JwtKeys;
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
|
|
|
|
let hotel_pools = HotelPool::new();
|
|
let logs_manager = SqliteConnectionManager::file("db/auth.sqlite");
|
|
let logs_pool = Pool::builder()
|
|
.max_size(5)
|
|
.build(logs_manager)
|
|
.expect("Failed to build logs pool");
|
|
|
|
let state = AppState {
|
|
hotel_pools,
|
|
logs_pool,
|
|
ws_map: Arc::new(DashMap::new()),
|
|
//jwt_secret: "your_jwt_secret_key s".to_string(), // better: load from env var
|
|
};
|
|
|
|
let jwt_secret = "your_jwt_secret_key".to_string();
|
|
let jwt_keys = JwtKeys {
|
|
encoding: EncodingKey::from_secret(jwt_secret.as_ref()),
|
|
decoding: DecodingKey::from_secret(jwt_secret.as_ref()),
|
|
};
|
|
|
|
|
|
|
|
let app = create_router(state)
|
|
.layer(Extension(jwt_keys));
|
|
|
|
let listener = TcpListener::bind("0.0.0.0:3000").await?;
|
|
serve(listener, app).into_future().await?;
|
|
Ok(())
|
|
}
|
|
|
|
async fn handler() -> &'static str {
|
|
"Hiii from localhost"
|
|
} |