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

URL in WindowManager.prepare_window() has double slashes #2281

Closed
woubuc opened this issue Jul 22, 2021 · 2 comments
Closed

URL in WindowManager.prepare_window() has double slashes #2281

woubuc opened this issue Jul 22, 2021 · 2 comments

Comments

@woubuc
Copy link
Contributor

woubuc commented Jul 22, 2021

Describe the bug

When a page URL is joined with the base URL, too many slashes are added, causing some dev servers (in my case, the Nuxt dev server) to return a 404 instead of showing the page.

With config..

"devPath": "http://localhost:3000",

..WindowManager.get_url() returns http://localhost:3000/ with a trailing slash, even though in the config file it doesn't have a trailing slash.

However, WindowManager.prepare_window() combines the base url with the path like this..

format!("{}/{}", url, path.to_string_lossy())

..which means that this code..

app.create_window(
    "login".into(),
    WindowUrl::App("login".into()),
    |builder, attrs| { [...] },
).unwrap();

..results in the webview trying to load http://localhost:3000//login because the format call adds an additional slash inbetween the base url and the path. This is a problem if the dev server doesn't normalise the path and just tries to match //login - resulting in a 404 instead of the expected page.

If I replace that format line in manager.rs in the Tauri project with the following, to prevent adding a slash inbetween the parts if the base url already has a trailing slash..

let separator = match url.ends_with("/") {
    true => "",
    false => "/",
};

format!("{}{}{}", url, separator, path.to_string_lossy())

..then I get http://localhost:3000/login and everything works as expected.

I don't know what platform and compatibility considerations the URLs in Tauri have, so I don't know if this fix would be applicable for all users and build targets. But if the above fix is acceptable I'll gladly create a pull request.

Platform and Versions (required):

Operating System - Windows, version 10.0.19042 X64
Webview2 - 91.0.864.71

Node.js environment
  Node.js - 14.16.0
  @tauri-apps/cli - 1.0.0-beta.6
  @tauri-apps/api - 1.0.0-beta.5

Global packages
  npm - 6.14.11
  yarn - 1.22.4

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/.idea
/.nuxt
/assets
/components
/dist
/i18n
/layouts
/node_modules
/pages
/plugins
/src-tauri
/static
/types
/utils

App
  tauri.rs - 1.0.0-beta.5
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-
eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../dist
  devPath - http://localhost:3000
  framework - Vue.js (Nuxt)
  bundler - Webpack
@amrbashir
Copy link
Member

amrbashir commented Jul 22, 2021

Thanks for the detailed explanation and investigation, a PR would be great.

woubuc added a commit to woubuc/tauri that referenced this issue Jul 22, 2021
@woubuc
Copy link
Contributor Author

woubuc commented Jul 22, 2021

Pull request opened in #2282

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

No branches or pull requests

2 participants