Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perseus rocket integration #266

Merged
merged 13 commits into from
Apr 6, 2023
3 changes: 2 additions & 1 deletion bonnie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ test.subcommands.cli.desc = "runs the cli tests (all are long-running, this will
test.subcommands.example-all-integrations.cmd = [
"EXAMPLE_INTEGRATION=actix-web bonnie dev example %category %example test",
"EXAMPLE_INTEGRATION=warp bonnie dev example %category %example test",
"EXAMPLE_INTEGRATION=axum bonnie dev example %category %example test"
"EXAMPLE_INTEGRATION=axum bonnie dev example %category %example test",
"EXAMPLE_INTEGRATION=rocket bonnie dev example %category %example test"
]
test.subcommands.example-all-integrations.args = [ "category", "example" ]
test.subcommands.example-all-integrations.desc = "tests a single example with all integrations (assumes geckodriver running in background)"
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions examples/core/custom_server_rocket/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "custom_server_rocket"
version = "0.4.0-beta.21"
Miroito marked this conversation as resolved.
Show resolved Hide resolved
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
perseus = { path = "../../../packages/perseus", features = ["hydrate"] }
sycamore = "^0.8.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[target.'cfg(engine)'.dev-dependencies]
fantoccini = "0.17"

[target.'cfg(engine)'.dependencies]
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] }
perseus-rocket = { path = "../../../packages/perseus-rocket", features = [ "dflt-server" ] }
rocket = "0.5.0-rc.2"

[target.'cfg(client)'.dependencies]
3 changes: 3 additions & 0 deletions examples/core/custom_server_rocket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Miroito marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions examples/core/custom_server_rocket/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
mod templates;

use perseus::prelude::*;

#[cfg(engine)]
mod api {
use rocket::get;

#[get("/hello")]
pub fn hello() -> String {
"Hello from an api".to_string()
}
}

#[cfg(engine)]
pub async fn dflt_server<
M: perseus::stores::MutableStore + 'static,
T: perseus::i18n::TranslationsManager + 'static,
>(
turbine: &'static perseus::turbine::Turbine<M, T>,
opts: perseus::server::ServerOptions,
(_host, port): (String, u16),
) {
use perseus_rocket::perseus_base_app;
use rocket::routes;
let mut app = perseus_base_app(turbine, opts).await;
app = app.mount("/api", routes![api::hello]);
let mut config = rocket::Config::default();
Miroito marked this conversation as resolved.
Show resolved Hide resolved
config.port = port;
app = app.configure(config);

match app.launch().await {
Err(e) => println!("Error lauching rocket app: {}", e),
_ => (),
}
}

#[perseus::main(dflt_server)]
pub fn main<G: Html>() -> PerseusApp<G> {
PerseusApp::new()
.template(crate::templates::index::get_template())
.error_views(ErrorViews::unlocalized_development_default())
}
23 changes: 23 additions & 0 deletions examples/core/custom_server_rocket/src/templates/index.rs
Miroito marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use perseus::prelude::*;
use sycamore::prelude::*;

fn index_page<G: Html>(cx: Scope) -> View<G> {
let counter = create_signal(cx, 0);
view! { cx,
(counter.get())
br () {}
button (on:click=move |_| {counter.set(*counter.get() - 1)}) { "remove 1"}
button (on:click=move |_| {counter.set(*counter.get() + 1)}) { "Add 1"}
}
}

#[engine_only_fn]
fn head(cx: Scope) -> View<SsrNode> {
view! { cx,
title { "Index Page" }
}
}

pub fn get_template<G: Html>() -> Template<G> {
Template::build("index").view(index_page).head(head).build()
}
1 change: 1 addition & 0 deletions examples/core/custom_server_rocket/src/templates/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod index;
2 changes: 2 additions & 0 deletions packages/perseus-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ edition = "2021"
perseus-actix-web = { path = "../perseus-actix-web", features = [ "dflt-server" ], optional = true }
perseus-warp = { path = "../perseus-warp", features = [ "dflt-server" ], optional = true }
perseus-axum = { path = "../perseus-axum", features = [ "dflt-server" ], optional = true }
perseus-rocket = { path = "../perseus-rocket", features = [ "dflt-server" ], optional = true }

[features]
default = [ "warp" ]

actix-web = [ "perseus-actix-web" ]
warp = [ "perseus-warp" ]
axum = [ "perseus-axum" ]
rocket = [ "perseus-rocket" ]
2 changes: 2 additions & 0 deletions packages/perseus-integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
pub use perseus_actix_web::dflt_server;
#[cfg(feature = "axum")]
pub use perseus_axum::dflt_server;
#[cfg(feature = "rocket")]
pub use perseus_rocket::dflt_server;
#[cfg(feature = "warp")]
pub use perseus_warp::dflt_server;
24 changes: 24 additions & 0 deletions packages/perseus-rocket/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "perseus-rocket"
version = "0.4.0-beta.21"
Miroito marked this conversation as resolved.
Show resolved Hide resolved
edition = "2021"
description = "An integration that makes the Perseus framework easy to use with Rocket."
authors = ["Miroito <alban.vachette@gmail.com", "arctic_hen7 <arctic_hen7@pm.me>"]
license = "MIT"
repository = "https://github.com/framesurge/perseus"
homepage = "https://framesurge.sh/perseus"
readme = "./README.md"
keywords = ["wasm", "frontend", "webdev", "ssg", "ssr"]
categories = ["wasm", "web-programming::http-server", "development-tools", "asynchronous", "gui"]

[dependencies]
perseus = { path = "../perseus", version = "0.4.0-beta.21"}
rocket = "0.5.0-rc.2"

[features]
# Enables the default server configuration, which provides a convenience function if you're not adding any extra routes
dflt-server = []

[package.metadata.docs.rs]
rustc-args = ["--cfg=engine"]
rustdoc-args = ["--cfg=engine"]
5 changes: 5 additions & 0 deletions packages/perseus-rocket/README.md
Miroito marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Perseus Rocket Integration

This is the official [Perseus](https://github.com/arctic-hen7/perseus) integration for making serving your apps on [Rocket](https://rocket.rs/) significantly easier!
Miroito marked this conversation as resolved.
Show resolved Hide resolved

If you're new to Perseus, you should check out [the core package](https://github.com/arctic-hen7/perseus) first.
1 change: 1 addition & 0 deletions packages/perseus-rocket/README.proj.md
Loading