#tauri-plugin #protocols #localhost #assets #default #expose #server

tauri-plugin-localhost

通过本地服务器而不是默认的自定义协议来公开您应用的资源

19 个版本

2.0.0-rc.02024 年 8 月 2 日
2.0.0-beta.92024 年 7 月 31 日
2.0.0-beta.62024 年 5 月 30 日
2.0.0-beta.32024 年 3 月 21 日
0.1.0 2022 年 6 月 19 日

181开发工具

Download history 106/week @ 2024-04-29 47/week @ 2024-05-06 29/week @ 2024-05-13 48/week @ 2024-05-20 303/week @ 2024-05-27 91/week @ 2024-06-03 88/week @ 2024-06-10 423/week @ 2024-06-17 184/week @ 2024-06-24 234/week @ 2024-07-01 208/week @ 2024-07-08 168/week @ 2024-07-15 705/week @ 2024-07-22 1068/week @ 2024-07-29 475/week @ 2024-08-05 396/week @ 2024-08-12

每月下载量 2,653
holochain_cli_launch 中使用

Apache-2.0 或 MIT

56KB
93

plugin-localhost

通过本地服务器而不是默认的自定义协议来公开您应用的资源。

注意:此插件存在相当大的安全风险,并且仅在您了解自己在做什么时才应使用它。如有疑问,请使用默认的自定义协议实现。

安装

此插件需要至少 1.75 版本的 Rust

我们可以推荐三种一般性的安装方法。

  1. 使用 crates.io 和 npm(最简单,但需要您信任我们的发布流程)
  2. 直接从 Github 使用 git 标签 / 修订哈希拉取源代码(最安全)
  3. 使用 Git 子模块将此仓库安装到您的 tauri 项目中,然后使用文件协议导入源代码(最安全,但使用不便)

通过在您的 Cargo.toml 文件中添加以下内容来安装核心插件

src-tauri/Cargo.toml

[dependencies]
portpicker = "0.1" # used in the example to pick a random free port
tauri-plugin-localhost = "2.0.0-rc"
# alternatively with Git:
tauri-plugin-localhost = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }

用法

首先您需要将核心插件在Tauri中注册

src-tauri/src/main.rs

use tauri::{Manager, 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| {
      app.ipc_scope().configure_remote_access(
        RemoteDomainAccessScope::new("localhost")
          .add_window("main")
      );

      let url = format!("https://127.0.0.1:{}", port).parse().unwrap();
      WindowBuilder::new(app, "main".to_string(), WindowUrl::External(url))
        .title("Localhost Example")
        .build()?;
      Ok(())
    })
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

贡献

接受PR。请在发起pull request之前务必阅读贡献指南。

合作伙伴

CrabNebula

有关赞助商的完整列表,请访问我们的网站Open Collective

许可证

代码:(c) 2015 - 现今 - 常见慈善机构内的Tauri项目。

适用于MIT或MIT/Apache 2.0。

依赖项

~17–60MB
~886K SLoC