Skip to content

Commit

Permalink
Merge pull request #56 from ogghead/template-add
Browse files Browse the repository at this point in the history
Implement 'add' functionality for template
  • Loading branch information
itowlson authored Dec 11, 2024
2 parents 9367ff8 + 587d697 commit ce648b5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
8 changes: 4 additions & 4 deletions templates/leptos-ssr/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["{{authors}}"]
description = "{{project-description}}"

[[trigger.http]]
route = "/..."
route = "{{http-path | http_wildcard}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
Expand All @@ -19,9 +19,9 @@ command = "cargo leptos build --release && LEPTOS_OUTPUT_NAME={{project-name | s
watch = ["src/**/*.rs", "Cargo.toml"]

[[trigger.http]]
route = "/pkg/..."
component = "pkg"
route = "{{http-path}}/pkg/..."
component = "{{project-name | kebab_case}}-pkg"

[component.pkg]
[component.{{project-name | kebab_case}}-pkg]
source = { url = "https://github.com/fermyon/spin-fileserver/releases/download/v0.1.0/spin_static_fs.wasm", digest = "sha256:96c76d9af86420b39eb6cd7be5550e3cb5d4cc4de572ce0fd1f6a29471536cb4" }
files = [{ source = "target/site/pkg", destination = "/" }]
10 changes: 5 additions & 5 deletions templates/leptos-ssr/content/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options=options.clone()/>
<HydrationScripts options=options.clone() root="{{http-path}}"/>
<MetaTags/>
</head>
<body>
Expand All @@ -30,16 +30,16 @@ pub fn App() -> impl IntoView {
let fallback = || view! { "Page not found." }.into_view();

view! {
<Stylesheet id="leptos" href="/pkg/{{project-name | snake_case}}.css"/>
<Stylesheet id="leptos" href="{{http-path}}/pkg/{{project-name | snake_case}}.css"/>
<Meta name="description" content="A website running its server-side as a WASI Component :D"/>

<Title text="Welcome to Leptos X Spin!"/>

<Router>
<main>
<Routes fallback>
<Route path=path!("") view=HomePage/>
<Route path=path!("/*any") view=NotFound/>
<Route path=path!("{{http-path}}") view=HomePage/>
<Route path=path!("{{http-path}}/*any") view=NotFound/>
</Routes>
</main>
</Router>
Expand Down Expand Up @@ -85,7 +85,7 @@ fn NotFound() -> impl IntoView {
view! { <h1>"Not Found"</h1> }
}

#[server]
#[server(prefix = "{{http-path}}/api")]
pub async fn save_count(count: u32) -> Result<(), ServerFnError<String>> {
println!("Saving value {count}");
let store = spin_sdk::key_value::Store::open_default().map_err(|e| e.to_string())?;
Expand Down
20 changes: 20 additions & 0 deletions templates/leptos-ssr/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[trigger.http]]
route = "{{http-path | http_wildcard}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{output-path}}/target/wasm32-wasip1/release/{{project-name | snake_case}}.wasm"
allowed_outbound_hosts = []
key_value_stores = ["default"]
[component.{{project-name | kebab_case}}.build]
command = "cargo leptos build --release && LEPTOS_OUTPUT_NAME={{project-name | snake_case}} cargo build --lib --target wasm32-wasip1 --release --no-default-features --features ssr"
workdir = "{{output-path}}"
watch = ["src/**/*.rs", "Cargo.toml"]

[[trigger.http]]
route = "{{http-path}}/pkg/..."
component = "{{project-name | kebab_case}}-pkg"

[component.{{project-name | kebab_case}}-pkg]
source = { url = "https://github.com/fermyon/spin-fileserver/releases/download/v0.1.0/spin_static_fs.wasm", digest = "sha256:96c76d9af86420b39eb6cd7be5550e3cb5d4cc4de572ce0fd1f6a29471536cb4" }
files = [{ source = "{{output-path}}/target/site/pkg", destination = "/" }]
7 changes: 6 additions & 1 deletion templates/leptos-ssr/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ tags = ["http", "rust", "leptos"]

[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
http-path = { type = "string", prompt = "HTTP path (if provided, should start with '/' and not end with '/')", default = "", pattern = "^$|^/\\S+$" }

[add_component]
skip_files = ["spin.toml"]
[add_component.snippets]
component = "component.txt"

0 comments on commit ce648b5

Please sign in to comment.