Skip to content

An official Tauri Plugin for using a localhost server in production apps.

License

Notifications You must be signed in to change notification settings

spirityy/tauri-plugin-localhost

 
 

Repository files navigation

Tauri Plugin Localhost

Test

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.

Installation

There are three general methods of installation that we can recommend.

  1. Pull sources directly from Github using git tags / revision hashes (most secure, good for developement, shown below)
  2. Git submodule install this repo in your tauri project and then use file protocol to ingest the source
  3. 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");
}

License

MIT / Apache-2.0

About

An official Tauri Plugin for using a localhost server in production apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%