From 5c8e50d17467b63d61ccf7d9138e523b9c4a271b Mon Sep 17 00:00:00 2001 From: arctic-hen7 Date: Sun, 9 Apr 2023 11:30:40 +1000 Subject: [PATCH] fix: cleaned up rocket integration Mainly just appeasing clippy, but also refactored the example server a little to make it more consistent with the inbuilt default server. --- examples/core/custom_server_rocket/.gitignore | 1 + examples/core/custom_server_rocket/README.md | 2 +- .../core/custom_server_rocket/src/main.rs | 14 ++++++------- packages/perseus-rocket/src/lib.rs | 21 ++++++++++--------- 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 examples/core/custom_server_rocket/.gitignore diff --git a/examples/core/custom_server_rocket/.gitignore b/examples/core/custom_server_rocket/.gitignore new file mode 100644 index 0000000000..849ddff3b7 --- /dev/null +++ b/examples/core/custom_server_rocket/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/examples/core/custom_server_rocket/README.md b/examples/core/custom_server_rocket/README.md index 22c2f3429e..c145d103aa 100644 --- a/examples/core/custom_server_rocket/README.md +++ b/examples/core/custom_server_rocket/README.md @@ -1,3 +1,3 @@ # Custom Server Rocket Example -This is an example of setting up a custom server using rocket with Perseus, with one example API route. +This is an example of setting up a custom server using Rocket with Perseus, with one example API route. diff --git a/examples/core/custom_server_rocket/src/main.rs b/examples/core/custom_server_rocket/src/main.rs index e9bc4ed662..818c110d5b 100644 --- a/examples/core/custom_server_rocket/src/main.rs +++ b/examples/core/custom_server_rocket/src/main.rs @@ -26,18 +26,18 @@ pub async fn dflt_server< let addr = host.parse().expect("Invalid address provided to bind to."); - let mut config = rocket::Config::default(); - let mut app = perseus_base_app(turbine, opts).await; app = app.mount("/api", routes![api::hello]); - config.address = addr; - config.port = port; + let config = rocket::Config { + port, + address: addr, + ..Default::default() + }; app = app.configure(config); - match app.launch().await { - Err(e) => println!("Error lauching rocket app: {}", e), - _ => (), + if let Err(err) = app.launch().await { + eprintln!("Error lauching Rocket app: {}.", err); } } diff --git a/packages/perseus-rocket/src/lib.rs b/packages/perseus-rocket/src/lib.rs index 7db6ba5705..da434a0af8 100644 --- a/packages/perseus-rocket/src/lib.rs +++ b/packages/perseus-rocket/src/lib.rs @@ -233,7 +233,7 @@ where Method::Get, "/translations/", RocketHandlerWithTurbine { - turbine: &turbine, + turbine, perseus_route: PerseusRouteKind::Locale, }, ); @@ -246,7 +246,7 @@ where Method::Get, "/", RocketHandlerWithTurbine { - turbine: &turbine, + turbine, perseus_route: PerseusRouteKind::IntialLoadHandler, }, ); @@ -255,7 +255,7 @@ where Method::Get, "/page/", RocketHandlerWithTurbine { - turbine: &turbine, + turbine, perseus_route: PerseusRouteKind::SubsequentLoadHandler, }, ); @@ -284,7 +284,7 @@ where Method::Get, url, RocketHandlerWithTurbine { - turbine: &turbine, + turbine, perseus_route: PerseusRouteKind::StaticAlias(static_path), }, ); @@ -311,13 +311,14 @@ pub async fn dflt_server println!("Error lauching rocket app: {}", e), - _ => (), + if let Err(err) = app.launch().await { + eprintln!("Error lauching Rocket app: {}.", err); } }