diff --git a/templates/leptos-ssr/content/spin.toml b/templates/leptos-ssr/content/spin.toml index c9beaa2..4487c3c 100644 --- a/templates/leptos-ssr/content/spin.toml +++ b/templates/leptos-ssr/content/spin.toml @@ -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}}] @@ -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 = "/" }] diff --git a/templates/leptos-ssr/content/src/app.rs b/templates/leptos-ssr/content/src/app.rs index f0084a8..f886f13 100644 --- a/templates/leptos-ssr/content/src/app.rs +++ b/templates/leptos-ssr/content/src/app.rs @@ -12,7 +12,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView { - + @@ -30,7 +30,7 @@ pub fn App() -> impl IntoView { let fallback = || view! { "Page not found." }.into_view(); view! { - + @@ -38,8 +38,8 @@ pub fn App() -> impl IntoView { <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> @@ -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())?; diff --git a/templates/leptos-ssr/metadata/snippets/component.txt b/templates/leptos-ssr/metadata/snippets/component.txt new file mode 100644 index 0000000..ad8a153 --- /dev/null +++ b/templates/leptos-ssr/metadata/snippets/component.txt @@ -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 = "/" }] diff --git a/templates/leptos-ssr/metadata/spin-template.toml b/templates/leptos-ssr/metadata/spin-template.toml index 811ad51..3ee4715 100644 --- a/templates/leptos-ssr/metadata/spin-template.toml +++ b/templates/leptos-ssr/metadata/spin-template.toml @@ -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*$" } \ No newline at end of file +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" \ No newline at end of file