Ver Fonte

fix(cli): Ignore query parameter in dev server (#8697)

* fix(cli): Ignore query parameter in dev server

fixes #8148
additional ref: https://discord.com/channels/616186924390023171/1201199918379974766

* Update .changes/cli-devserver-queryparam.md

---------

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Fabian-Lars há 1 ano atrás
pai
commit
0bff8c325d

+ 6 - 0
.changes/cli-devserver-queryparam.md

@@ -0,0 +1,6 @@
+---
+"tauri-cli": patch:bug
+"@tauri-apps/cli": patch:bug
+---
+
+Fix the built-in dev server failing to serve files when URL had queries `?` and other url components.

+ 5 - 3
tooling/cli/src/helpers/web_dev_server.rs

@@ -123,11 +123,13 @@ pub fn start_dev_server<P: AsRef<Path>>(path: P, port: Option<u16>) -> crate::Re
 }
 
 async fn handler(uri: axum::http::Uri, state: Arc<State>) -> impl IntoResponse {
-  let uri = uri.to_string();
+  // Frontend files should not contain query parameters. This seems to be how vite handles it.
+  let uri = uri.path();
+
   let uri = if uri == "/" {
-    &uri
+    uri
   } else {
-    uri.strip_prefix('/').unwrap_or(&uri)
+    uri.strip_prefix('/').unwrap_or(uri)
   };
 
   let file = std::fs::read(state.serve_dir.join(uri))