websockets
This commit is contained in:
parent
b44e4ed6f9
commit
f0b53b67ce
9 changed files with 268 additions and 28 deletions
|
|
@ -1,5 +1,6 @@
|
|||
pub mod auth;
|
||||
pub mod chat;
|
||||
pub mod notifications;
|
||||
pub mod tasks;
|
||||
|
||||
use axum::{
|
||||
|
|
@ -24,6 +25,7 @@ pub struct AppState {
|
|||
pub config: Arc<crate::config::Config>,
|
||||
pub verifier: Arc<crate::domain::auth::JwksVerifier>,
|
||||
pub authenticator: Arc<crate::domain::auth::Authenticator>,
|
||||
pub tx: tokio::sync::broadcast::Sender<crate::server::notifications::WsEvent>,
|
||||
}
|
||||
|
||||
pub async fn start(config: crate::config::Config) -> AppResult<()> {
|
||||
|
|
@ -31,8 +33,10 @@ pub async fn start(config: crate::config::Config) -> AppResult<()> {
|
|||
|
||||
let config = Arc::new(config);
|
||||
|
||||
let (tx, _) = tokio::sync::broadcast::channel(100);
|
||||
|
||||
let scheduler = Arc::new(
|
||||
Scheduler::new(db.clone(), config.clone())
|
||||
Scheduler::new(db.clone(), config.clone(), tx.clone())
|
||||
.await
|
||||
.map_err(|e| crate::error::AppError::Internal(e.to_string()))?,
|
||||
);
|
||||
|
|
@ -56,6 +60,7 @@ pub async fn start(config: crate::config::Config) -> AppResult<()> {
|
|||
config: config.clone(),
|
||||
verifier,
|
||||
authenticator,
|
||||
tx,
|
||||
});
|
||||
|
||||
let app = build_app(state, &config);
|
||||
|
|
@ -122,6 +127,7 @@ fn build_app(state: Arc<AppState>, config: &crate::config::Config) -> Router {
|
|||
.route("/api/auth/refresh", post(auth::auth_refresh))
|
||||
.route("/api/auth/logout", post(auth::auth_logout))
|
||||
.route("/api/chat", post(chat::chat_handler))
|
||||
.route("/api/ws", get(notifications::ws_handler))
|
||||
.layer(cors)
|
||||
.layer(tower_http::set_header::SetResponseHeaderLayer::overriding(
|
||||
axum::http::header::CONTENT_SECURITY_POLICY,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue