tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
84.71k stars 2.55k forks source link

[bug] Unable to Interact with Server via HTTP in Production, Works Fine in Development #11081

Closed XPein closed 4 weeks ago

XPein commented 1 month ago

Describe the bug

build my app with "cargo tauri dev", my application successfully interacts with the server via HTTP. However, after deploying the same code to the production environment, HTTP communication with the server fails:fetch failed . The codebase is identical in both environments, so the issue may be related to product configurations.

Reproduction

allowlist:

"allowlist": {
  "all": true,
  "http": {
    "all": true,
    "request": true,
    "scope": ["http://8.137.95.15:5000"]
  }
},

run "cargo tauri build" and run target/release/xxx.exe can not interact with sever, because fetch error. run "cargo tauri dev" and run app, can interact with server

Expected behavior

No response

Full tauri info output

warning: `C:\Users\User\.cargo\config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
WARNING: no lock files found, defaulting to npm

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 128.0.2739.79
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)
    - node: 20.17.0
    - pnpm: 9.10.0
    - npm: 10.8.3

[-] Packages
    - tauri [RUST]: 1.8.0
    - tauri-build [RUST]: 1.5.5
    - wry [RUST]: 0.24.11
    - tao [RUST]: 0.16.10
    - tauri-cli [RUST]: 1.6.1
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 1.6.1 (outdated, latest: 1.6.2)

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../UI
    - devPath: ../UI

Stack trace

No response

Additional context

No response

lucasfernog commented 1 month ago

Do you have CORS set up on that server? On production your app URL is not a localhost URL (http://localhost:someport) but http://tauri.localhost on Windows/Android and tauri://localhost on other platforms.

lcdss commented 1 month ago

I had a similar problem recently and in my tests, while developing on Linux I got the following origins:

http://localhost:1420 -> Browser and Linux dev builds http://tauri.localhost -> Android dev, debug and release builds; Linux debug build tauri://localhost -> Linux release build

My android app couldn't do fetch my local API, and that only happened with release builds, so after debugging I found out that the problems was the value of usesCleartextTraffic. On release builds the value is false, which means that the "access" to non encrypted resources are blocked, so you would need to change your API scheme to https or change the value of usesCleartextTraffic to true.

FabianLars commented 4 weeks ago

Closing due to inactivity. Will re-open once OP answered Lucas' question.

P.S. since you're on v1, try this setting too https://v1.tauri.app/v1/api/config/#securityconfig.dangeroususehttpscheme