Files
leptos/examples
Tommy Yu b13f1f6313 feat: provide tower services for serving static files (#4528)
* Remove unused example module.

* Helpers for setting up site pkg static routes

- This provides a function that construct an underlying `ServeDir`
  service and a function that constructs the typical path to serve the
  assets from.

* Provide the error handler as a service

- Combined with the previous static ServeDir service, these two can work
  together to provide the existing functionality, or be combined with
  other tower services to allow more control and flexibility as they may
  be composed with other services, while `file_and_error_handler` does
  not permit such a level of reuse.

* Need to test default feature manually.

- For whatever reason the default feature isn't automatically added by
  `cargo-all-features`.

* Integration tests for `leptos_axum`.

- Ensure the different ways to configure the services are tested to be
  sure they will keep serving asset files and the expected error pages.

* Test for #4394

- This is separated out mostly to show how a new test case might be
  added for an integration case viewable as a patch.

* Configure cargo-nextest to make new tests work

- Refer to comments added to relevant files for the issue this fixes.

* Remove hardcoding ports for axum test services

- Manuallying specifying ports will become annoying to keep track of for
  every different tests, instead require the server to report the port
  it started with and have parse that output into a helper type, which
  in turn provides a method to construct uri required for testing.

* Improve `cargo-nextest` setup for leptos_axum

- Define `cargo-nextest` setup-script for the leptos_axum integration
  tests so that `cargo leptos build` will run for the intended target,
  while also disable the running of that by the test itself if the
  environment variable associated with `cargo-nextest` is set.
- Instead of doing it directly from cargo as a more cross-platform
  approach, using an actual script must be done given the need to pass
  the environment variable in, hence both shell script and batch file
  are provided.
2026-01-15 19:53:49 -05:00
..
2026-01-15 19:34:09 -05:00
2025-11-11 15:51:21 -05:00

Examples README

Main Branch

The examples in this directory are all built and tested against the current main branch.

To the extent that new features have been released or breaking changes have been made since the previous release, the examples are compatible with the main branch and not the current release.

Getting Started

The simplest way to get started with any example is to use the “quick start” command found in the README for each example. Most of the examples use either trunk (a simple build system and dev server for client-side-rendered apps) or cargo-leptos (a build system for server-rendered and client-hydrated apps).

Using Cargo Make

You can also run any of the examples using cargo-make. Note that this is completely optional. We use it for CI, and it can be convenient for running the examples, but is not required.

Follow these steps to get any example up and running.

  1. cd to the example you want to run
  2. Make sure cargo-make is installed (for example by running cargo install cargo-make)
  3. Make sure rustup target add wasm32-unknown-unknown was executed for the currently selected toolchain.
  4. Run cargo make ci to setup and test the example
  5. Run cargo make start to run the example
  6. Open the client URL in the console output (http://127.0.0.1:8080 or http://127.0.0.1:3000 by default)
  7. Run cargo make stop to end any processes started by cargo make start.

Here are a few additional notes:

  • Extendable custom task files are located in the cargo-make directory
  • Running a task will automatically install cargo dependencies
  • Each Makefile.toml file must extend the cargo-make/main.toml file
  • cargo-make files that end in *-test.toml configure web testing strategies
  • Run cargo make test-report to learn which examples have web tests

Prerequisites

Example projects depend on the following tools. Please install them as needed.

  • Rust
  • Nightly Rust
    • Run rustup toolchain install nightly
    • Run rustup target add wasm32-unknown-unknown
  • Cargo Make
    • Run cargo install --force cargo-make
    • Setup a command alias like alias cm='cargo make' to reduce typing (Optional)
  • Trunk
    • Run cargo install trunk
  • Node Version Manager (Optional)
  • Node.js
  • pnpm (Optional)