live.umm.gay/wish-server-rs/src/main.rs

58 lines
1.4 KiB
Rust

use miette::{Context, IntoDiagnostic, Result};
use std::{net::SocketAddr, sync::Arc};
use axum::{routing, Router};
use tower_http::{
cors::{Any, CorsLayer},
trace::TraceLayer,
};
mod streams;
mod util;
mod wish;
use crate::wish::{setup_webrtc, whep::handle_whep, whip::handle_whip};
#[derive(Clone)]
pub struct AppState {
pub webrtc: Arc<webrtc::api::API>,
pub db: Arc<&'static str>,
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let webrtc = Arc::new(setup_webrtc()?);
let app_state = AppState {
webrtc,
db: Arc::new("ooo weee i'm the data base!!!"), // TODO: sqlx
};
let app = Router::new()
.route("/api/wish-server/whip", routing::any(handle_whip))
.route("/api/wish-server/whep", routing::any(handle_whep))
.layer(TraceLayer::new_for_http())
.layer(
CorsLayer::new()
.allow_methods(Any)
.allow_origin(Any)
.allow_headers(Any),
)
.with_state(app_state);
let bind_addr: SocketAddr = "127.0.0.1:3001"
.parse()
.into_diagnostic()
.wrap_err("Couldn't parse bind address")?;
println!("Listening at http://{bind_addr}/ ...");
axum::Server::bind(&bind_addr)
.serve(app.into_make_service())
.await
.unwrap();
Ok(())
}