A Tauri Plugin that allows your application to use a localhost server instead of Tauri's custom protocol (tauri://localhost
on Linux and macOS and https://tauri.localhost
on Windows).
Note that for security reasons Tauri recommends the custom protocol implementation. Use a localhost server only if it is really needed and be careful with your assets.
There are three general methods of installation that we can recommend.
- Pull sources directly from Github using git tags / revision hashes (most secure, good for developement, shown below)
- Git submodule install this repo in your tauri project and then use
file
protocol to ingest the source - Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
For more details and usage see the example app.
Please note, below in the dependencies you can also lock to a revision/tag in the Cargo.toml
.
src-tauri/Cargo.toml
[dependencies]
tauri = "1.0.0"
tauri-plugin-localhost = "0.1.0"
portpicker = "0.1"
Use in src-tauri/src/main.rs
:
use tauri::{window::WindowBuilder, WindowUrl};
fn main() {
let port = portpicker::pick_unused_port().expect("failed to find unused port");
tauri::Builder::default()
.plugin(tauri_plugin_localhost::Builder::new(port).build())
.setup(move |app| {
WindowBuilder::new(
app,
"main".to_string(),
WindowUrl::External(format!("http://localhost:{}", port).parse().unwrap()),
)
.title("Localhost Example")
.build()?;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
MIT / Apache-2.0