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>
This commit is contained in:
Fabian-Lars 2024-01-29 13:58:23 +01:00 committed by GitHub
parent a9b2c0625c
commit 0bff8c325d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -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.

View File

@ -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))