use super::handler; use crate::utils::filter::with_context; use crate::utils::structs::Context; use warp::{Filter, Rejection, Reply}; pub fn routes(context: Context) -> impl Filter + Clone { let cors = warp::cors().allow_any_origin(); static_files().or(index(context)).with(cors) } fn index(context: Context) -> impl Filter + Clone { // let real_client_ip = warp::header::optional::("X-Real-IP"); let real_client_ip = warp::addr::remote(); let accept_application_json_header = warp::header::header("Accept"); let cors = warp::cors().allow_any_origin(); warp::path::end().and( accept_application_json_header .and_then(handler::relay_config) .with(&cors) .or(warp::ws() .and(with_context(context)) .and(real_client_ip) .and_then(handler::ws_handler) .with(&cors)), ) } fn static_files() -> impl Filter + Clone { let mut exe_dir = std::env::current_exe().unwrap(); exe_dir.pop(); let mut www = exe_dir.clone(); www.pop(); www.push(std::path::Path::new("www/static")); warp::get().and(warp::fs::dir(www)) }