leptos/examples/errors_axum
Elliot Waite a9f778459a
examples: remove duplicate `console_error_panic_hook::set_once()` calls (#692)
2023-03-17 16:27:24 -04:00
..
public Update ErrorBoundary to use miette::Diagnostic instead of Error, and various other tweaks (#401) 2023-01-31 21:56:42 -05:00
src examples: remove duplicate `console_error_panic_hook::set_once()` calls (#692) 2023-03-17 16:27:24 -04:00
Cargo.toml chore: apply `cargo machete` systematically (#671) 2023-03-13 10:16:20 -04:00
LICENSE Update ErrorBoundary to use miette::Diagnostic instead of Error, and various other tweaks (#401) 2023-01-31 21:56:42 -05:00
Makefile.toml Switch examples to `check` instead of `build` (for CI resources) and add missing examples (#437) 2023-02-01 20:36:37 -05:00
README.md Several Minor Updates on Examples (#427) 2023-02-01 19:20:34 -05:00
style.css Update ErrorBoundary to use miette::Diagnostic instead of Error, and various other tweaks (#401) 2023-01-31 21:56:42 -05:00

README.md

Leptos Errors Demonstration with Axum

This example demonstrates how Leptos Errors can work with an Axum backend on a server.

Client Side Rendering

This example cannot be built as a trunk standalone CSR-only app as it requires the server to send status codes.

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