Run An Axum Web Server With Live Reload From Tauri
January 2024
This is how I'm embedding Axum server with hot reload in a Tauri app:
Cargo.toml
[package]
name = "tauri_with_axum"
version = "0.0.1"
description = "Tauri With Axum Embedded"
license = ""
repository = ""
edition = "2021"
[build-dependencies]
tauri-build = { version = "1.5", features = [] }
[dependencies]
tauri = { version = "1.5", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
axum = "0.7.4"
tower-http = { version = "0.5.1", features = ["fs"] }
tower-livereload = "0.9.1"
tokio = { version = "1.35.1"}
notify = "6.1.1"
notify-debouncer-mini = "0.4.1"
[features]
# this feature is used for production builds or when ``devPath`` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]src/main.rs
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
use Router;
use Watcher;
use Path;
use ServeDir;
use LiveReloadLayer;
async Notes
-
The examples for axum and tower/tower_http have a lot of
Result<(), Box<dyn std::error::Error>>in them with?at the end of theawaitstatments. I couldn't figure out how to get that to work so I fell back toif let - There's probaby other refinements that could be made, but this is working for me.
end of line
References
This is what I'm using for the Neopoligen control panel
The web server that's embedded in Tauri with this process
The glue between Axum and tower_livereload
The middleware that doest the hot reload of the web pages when they change on disk