Skip to content

Commit

Permalink
fix(cli): Ignore query parameter in dev server (#8697)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
FabianLars and amrbashir authored Jan 29, 2024
1 parent a9b2c06 commit 0bff8c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-devserver-queryparam.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 5 additions & 3 deletions tooling/cli/src/helpers/web_dev_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 0bff8c3

Please sign in to comment.