diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..7235f9e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,53 @@ +use crate::cli::{Listen, ListenFdSocket, ListenFdSockets}; +use actix_session::{storage::CookieSessionStore, SessionMiddleware}; +use actix_web::{cookie::Key, web, App, HttpServer}; +use clap::Parser; +use listenfd::ListenFd; + +mod app; +mod cli; +mod client; +mod config; + +pub async fn main() -> eyre::Result<()> { + env_logger::init(); + let mut listenfd = ListenFd::from_env(); + color_eyre::install()?; + let mut args = cli::CLI::parse(); + args.resolve(&mut listenfd).await?; + log::info!("retrieved config from auth servers"); + let config = web::Data::new(args.config); + let cookie_session_key = Key::generate(); + let mut server = HttpServer::new(move || { + let cookie_session = + SessionMiddleware::builder(CookieSessionStore::default(), cookie_session_key.clone()) + .cookie_name("session".into()) + .build(); + App::new() + .wrap(cookie_session) + .app_data(config.clone()) + .configure(app::all_services) + }); + let Listen { + listen_tcp, + listen_unix, + listen_fd, + } = &mut args.listen; + for sock in listen_tcp.iter() { + server = server.bind_auto_h2c(sock)?; + } + for sock in listen_unix.iter() { + server = server.bind_uds(sock)?; + } + if let Some(ListenFdSockets(sockets)) = listen_fd { + for sock in sockets.drain(..) { + server = match sock { + ListenFdSocket::Tcp(sock) => server.listen_auto_h2c(sock)?, + ListenFdSocket::Unix(sock) => server.listen_uds(sock)?, + }; + } + } + log::info!("started server"); + server.run().await?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index cf1ea69..63e8370 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,54 +1,4 @@ -use crate::cli::{Listen, ListenFdSocket, ListenFdSockets}; -use actix_session::{storage::CookieSessionStore, SessionMiddleware}; -use actix_web::{cookie::Key, web, App, HttpServer}; -use clap::Parser; -use listenfd::ListenFd; - -mod app; -mod cli; -mod client; -mod config; - #[tokio::main] async fn main() -> eyre::Result<()> { - env_logger::init(); - let mut listenfd = ListenFd::from_env(); - color_eyre::install()?; - let mut args = cli::CLI::parse(); - args.resolve(&mut listenfd).await?; - log::info!("retrieved config from auth servers"); - let config = web::Data::new(args.config); - let cookie_session_key = Key::generate(); - let mut server = HttpServer::new(move || { - let cookie_session = - SessionMiddleware::builder(CookieSessionStore::default(), cookie_session_key.clone()) - .cookie_name("session".into()) - .build(); - App::new() - .wrap(cookie_session) - .app_data(config.clone()) - .configure(app::all_services) - }); - let Listen { - listen_tcp, - listen_unix, - listen_fd, - } = &mut args.listen; - for sock in listen_tcp.iter() { - server = server.bind_auto_h2c(sock)?; - } - for sock in listen_unix.iter() { - server = server.bind_uds(sock)?; - } - if let Some(ListenFdSockets(sockets)) = listen_fd { - for sock in sockets.drain(..) { - server = match sock { - ListenFdSocket::Tcp(sock) => server.listen_auto_h2c(sock)?, - ListenFdSocket::Unix(sock) => server.listen_uds(sock)?, - }; - } - } - log::info!("started server"); - server.run().await?; - Ok(()) + subscribe_list::main().await }