diamond-in's picture
Update src/main.rs
ef98263 verified
raw
history blame contribute delete
979 Bytes
use axum::{routing::{get, post}, Router};
use tower_http::services::ServeDir;
use std::sync::Arc;
use tokio::sync::broadcast;
mod agent;
mod browser;
mod sse;
mod ui;
pub struct AppState {
pub tx: broadcast::Sender<String>,
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
// Channel for streaming logs and browser frames to UI
let (tx, _) = broadcast::channel(100);
let state = Arc::new(AppState { tx });
let app = Router::new()
.route("/api/chat", post(agent::chat_handler))
.route("/api/stream", get(sse::stream::sse_handler))
// Serve the React frontend from the dist folder
.fallback_service(ServeDir::new("./frontend/dist"))
.with_state(state);
// Axum 0.7 way to start the server
let listener = tokio::net::TcpListener::bind("0.0.0.0:7860").await.unwrap();
println!("πŸš€ Agent Server running on http://0.0.0.0:7860");
axum::serve(listener, app).await.unwrap();
}