diff options
Diffstat (limited to 'crates/rocie-server/src/main.rs')
| -rw-r--r-- | crates/rocie-server/src/main.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/rocie-server/src/main.rs b/crates/rocie-server/src/main.rs index af36c9e..8e10763 100644 --- a/crates/rocie-server/src/main.rs +++ b/crates/rocie-server/src/main.rs @@ -1,3 +1,4 @@ +use actix_cors::Cors; use actix_web::{App, HttpServer, middleware::Logger, web::Data}; use clap::Parser; use utoipa::OpenApi; @@ -49,6 +50,7 @@ async fn main() -> Result<(), std::io::Error> { host, port, db_path, + print_port, } => { let data = Data::new( app::App::new(db_path) @@ -56,10 +58,10 @@ async fn main() -> Result<(), std::io::Error> { .map_err(|err| std::io::Error::other(main::Error::AppInit(err)))?, ); - eprintln!("Serving at http://{host}:{port}"); - - HttpServer::new(move || { + let srv = HttpServer::new(move || { App::new() + // TODO: Remove before an actual deploy <2025-09-26> + .wrap(Cors::permissive()) .wrap(Logger::new( r#"%a "%r" -> %s %b ("%{Referer}i" "%{User-Agent}i" %T s)"#, )) @@ -67,9 +69,17 @@ async fn main() -> Result<(), std::io::Error> { .configure(api::get::register_paths) .configure(api::set::register_paths) }) - .bind((host, port))? - .run() - .await + .bind((host, port.unwrap_or(0)))?; + + let addr = srv.addrs()[0]; + let run = srv.run(); + + if print_port { + println!("{}", addr.port()); + } + eprintln!("Serving at http://{addr}"); + + run.await } Command::OpenApi => { let openapi = ApiDoc::openapi(); |
