leptos/examples/todo_app_sqlite_viz
agilarity 9997487a9c
test: lint examples with --all-features (#1008)
* test: lint all features

* fix(counter_isomorphic): check-style issues

* fix(errors_axum): check-style issues

* fix(hackernews): check-style issues

* fix(hackernews_axum): check-style issues

* fix(session_auth_axum): check-style issues

* build(session_auth_axum): add common tasks

* fix(ssr_modes): check-style issues

* build(ssr_modes_axum): add common tasks

* fix(ssr_modes_axum): check-style issues

* build(tailwind): add common tasks

* fix(tailwind): check-style issues

* fix(todo_app_sqlite_axum): check-style issues

* fix(todo_app_sqlite_viz): check-style issues
2023-05-05 22:25:29 -04:00
..
migrations feat: viz integration (#506) 2023-02-21 12:29:15 -05:00
public feat: viz integration (#506) 2023-02-21 12:29:15 -05:00
src test: lint examples with --all-features (#1008) 2023-05-05 22:25:29 -04:00
Cargo.toml chore: Upgrade console_log to stable (#724) 2023-03-22 18:21:53 -04:00
LICENSE feat: viz integration (#506) 2023-02-21 12:29:15 -05:00
Makefile.toml fix: lint issues in todo_app_sqlite_viz example (#1000) 2023-05-05 11:27:38 -04:00
README.md feat: viz integration (#506) 2023-02-21 12:29:15 -05:00
style.css feat: viz integration (#506) 2023-02-21 12:29:15 -05:00
Todos.db feat: viz integration (#506) 2023-02-21 12:29:15 -05:00

Leptos Todo App Sqlite with Viz

This example creates a basic todo app with a Viz backend that uses Leptos' server functions to call sqlx from the client and seamlessly run it on the server.

Client Side Rendering

This example cannot be built as a trunk standalone CSR-only app. Only the server may directly connect to the database.

Server Side Rendering with cargo-leptos

cargo-leptos is now the easiest and most featureful way to build server side rendered apps with hydration. It provides automatic recompilation of client and server code, wasm optimisation, CSS minification, and more! Check out more about it here

  1. Install cargo-leptos
cargo install --locked cargo-leptos
  1. Build the site in watch mode, recompiling on file changes
cargo leptos watch

Open browser on http://localhost:3000/

  1. When ready to deploy, run
cargo leptos build --release

Server Side Rendering without cargo-leptos

To run it as a server side app with hydration, you'll need to have wasm-pack installed.

  1. Edit the [package.metadata.leptos] section and set site-root to ".". You'll also want to change the path of the <StyleSheet / > component in the root component to point towards the CSS file in the root. This tells leptos that the WASM/JS files generated by wasm-pack are available at ./pkg and that the CSS files are no longer processed by cargo-leptos. Building to alternative folders is not supported at this time. You'll also want to edit the call to get_configuration() to pass in Some(Cargo.toml), so that Leptos will read the settings instead of cargo-leptos. If you do so, your file/folder names cannot include dashes.
  2. Install wasm-pack
cargo install wasm-pack
  1. Build the Webassembly used to hydrate the HTML from the server
wasm-pack build --target=web --debug --no-default-features --features=hydrate
  1. Run the server to serve the Webassembly, JS, and HTML
cargo run --no-default-features --features=ssr