Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localhost plugin failed to solve the problem of sending http requests in build production #1602

Closed
rust-kotlin opened this issue Jul 30, 2024 · 3 comments

Comments

@rust-kotlin
Copy link

Hi, everybody. I am in Windows and I used axios to successfully send http api requests in dev mode. When I am in build mode, my api requests failed.

I refered to this issue and properly configured the tauri-plugin-localhost
The config file:

    "allowlist": {
      "all": false,
      "http": {
        "all": true,
        "request": true,
        "scope": ["http://**", "https://**"]
      }
    },
    "security": {
      "csp": null,
      "dangerousUseHttpScheme": true,
      "dangerousRemoteDomainIpcAccess": [
        {
          "domain": "localhost",
          "windows": ["main"],
          "enableTauriAPI": true
        }
      ]
    },

when I am in dev mode, the http api request succeeded like this
image
image

while I am in build mode, the http api looked this. I only got a error page html back
image
image

From my perspective, the only difference between these two requests is their remote address. In build mode, the remote address is in ipv6 format. I don't know the reason and effect somehow.

Here is my tauri info

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 126.0.2592.113
    ✔ MSVC: Visual Studio Enterprise 2022
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 16.20.2
    - yarn: 1.22.22
    - npm: 8.19.4

[-] Packages
    - tauri [RUST]: 1.7.1
    - tauri-build [RUST]: 1.5.3
    - wry [RUST]: 0.24.10
    - tao [RUST]: 0.16.9
    - @tauri-apps/api [NPM]: 1.6.0
    - @tauri-apps/cli [NPM]: 1.6.0

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../docs
    - devPath: http://localhost:8080/
    - framework: Vue.js (Vue CLI)
    - bundler: Webpack
Done in 17.26s.
@FabianLars
Copy link
Member

tauri-plugin-http is not enough to make SSR features of your frontend framework work. It's still a static http server so api calls still won't work. For that you'll need to sidecar your frontend server somehow.

In dev mode those requests are handled by your frontend server already, that's why it's working there.

@FabianLars FabianLars closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2024
@rust-kotlin
Copy link
Author

tauri-plugin-http is not enough to make SSR features of your frontend framework work. It's still a static http server so api calls still won't work. For that you'll need to sidecar your frontend server somehow.

In dev mode those requests are handled by your frontend server already, that's why it's working there.

Thanks for your advice. So is there any easy way to solve this problem of http apis not working in build mode.

I tried to use the fetch api provided by tauri http but I think it was too disrupting a job to rewrite so much apis, or perhaps I should try to sidecar somehow following your instrutions. Or Tauri v2 solved this problem?

@rust-kotlin
Copy link
Author

Ah, sorry! In fact this application isn't in ssr, the problem is either about the http requests, and I seemed to find the real problem.

When I am in dev mode, the webpack serves and helps me do some reverse proxy job to send the requests to the backend in production. While in build mode, I don't have such a backend server to do some reverse proxy.
In Vue, it's defined like this:

  devServer: {
    proxy: {
      '^/api': {
        target: 'https://.../',
        ws: true,
        changeOrigin: true
      }
    }
  }

I believe I could run a actix or axum backend server to do the reverse proxy job when I build my production release to pass the cors security wall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants