Tauri http/https混用导致的请求失败的问题

vite方案

因为在项目里是需要使用http请求的,如果进行发布就会发现他的内置协议是https,导致http的请求发不出
方案
使用插件

https://github.com/tauri-apps/plugins-workspace/tree/v1/plugins/localhost

注意,我发现会闪退, 文档上的例子去掉setup就好了(不知道为啥)
路径:src-tauri->src->min.rs

use tauri::{utils::config::AppUrl, window::WindowBuilder, WindowUrl};

fn main() {
  let port = portpicker::pick_unused_port().expect("failed to find unused port");

  let mut context = tauri::generate_context!();
  let url = format!("http://localhost:{}", port).parse().unwrap();
  let window_url = WindowUrl::External(url);
  // rewrite the config so the IPC is enabled on this URL
  context.config_mut().build.dist_dir = AppUrl::Url(window_url.clone());

  tauri::Builder::default()
    .plugin(tauri_plugin_localhost::Builder::new(port).build())
    .run(context)
    .expect("error while running tauri application");
}

另外 我在做的时候发现奇怪的跨域问题, 检查你是不是开了全局梯子(被这个坑了半天) 或者 服务器没开跨域

posted @ 2024-02-15 18:59  Z_DK  阅读(205)  评论(0编辑  收藏  举报