leptos/examples/todo_app_sqlite_axum
Joseph Cruz 8c5ab99fa7
build(examples): pull up compile tasks (#1417)
* build(examples): pull up compile tasks

* build(examples): set toolchain for compiles tasks

* build(examples): set toolchain for build and check

* build(examples): set toolchain of other examples
2023-07-24 11:35:34 -04:00
..
migrations Move the examples out of the workspace, and standardize naming. All of the SSR examples now work with cargo-leptos 2022-12-31 15:52:19 -08:00
public Add Favicons to all the examples and standardize on the public folder for public assets 2023-01-09 15:27:52 -08:00
src docs/examples: use shorthand form for <Route/> views when possible (#1375) 2023-07-20 16:28:43 -04:00
Cargo.toml change: migrate to nightly and csr features rather than stable and default-features = false (#1227) 2023-06-26 21:12:14 -04:00
LICENSE Move the examples out of the workspace, and standardize naming. All of the SSR examples now work with cargo-leptos 2022-12-31 15:52:19 -08:00
Makefile.toml build(examples): pull up compile tasks (#1417) 2023-07-24 11:35:34 -04:00
README.md Update ErrorBoundary to use miette::Diagnostic instead of Error, and various other tweaks (#401) 2023-01-31 21:56:42 -05:00
style.css feat: provide Request<_> in context for Axum, enabling easier extractor use (#632) 2023-03-10 17:28:32 -05:00
Todos.db Move the examples out of the workspace, and standardize naming. All of the SSR examples now work with cargo-leptos 2022-12-31 15:52:19 -08:00

Leptos Todo App Sqlite with Axum

This example creates a basic todo app with an Axum 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