Skip to content

Commit

Permalink
fix: cleaned up rocket integration
Browse files Browse the repository at this point in the history
Mainly just appeasing clippy, but also refactored the example server a
little to make it more consistent with the inbuilt default server.
  • Loading branch information
arctic-hen7 committed Apr 9, 2023
1 parent f9ce9e0 commit 5c8e50d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions examples/core/custom_server_rocket/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
2 changes: 1 addition & 1 deletion examples/core/custom_server_rocket/README.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 7 additions & 7 deletions examples/core/custom_server_rocket/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
21 changes: 11 additions & 10 deletions packages/perseus-rocket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ where
Method::Get,
"/translations/<path..>",
RocketHandlerWithTurbine {
turbine: &turbine,
turbine,
perseus_route: PerseusRouteKind::Locale,
},
);
Expand All @@ -246,7 +246,7 @@ where
Method::Get,
"/<path..>",
RocketHandlerWithTurbine {
turbine: &turbine,
turbine,
perseus_route: PerseusRouteKind::IntialLoadHandler,
},
);
Expand All @@ -255,7 +255,7 @@ where
Method::Get,
"/page/<path..>",
RocketHandlerWithTurbine {
turbine: &turbine,
turbine,
perseus_route: PerseusRouteKind::SubsequentLoadHandler,
},
);
Expand Down Expand Up @@ -284,7 +284,7 @@ where
Method::Get,
url,
RocketHandlerWithTurbine {
turbine: &turbine,
turbine,
perseus_route: PerseusRouteKind::StaticAlias(static_path),
},
);
Expand All @@ -311,13 +311,14 @@ pub async fn dflt_server<M: MutableStore + 'static, T: TranslationsManager + 'st

let mut app = perseus_base_app(turbine, opts).await;

let mut config = rocket::Config::default();
config.port = port;
config.address = addr;
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);
}
}

0 comments on commit 5c8e50d

Please sign in to comment.