only proxy when actually using dev server

This commit is contained in:
Lucas Nogueira
2025-11-06 08:51:18 -03:00
parent 6565c49e61
commit 8801df6b5c
2 changed files with 14 additions and 5 deletions

View File

@@ -410,7 +410,11 @@ impl<R: Runtime> WebviewManager<R> {
let mut url = match &pending.webview_attributes.url {
WebviewUrl::App(path) => {
let app_url = app_manager.get_url(pending.webview_attributes.use_https_scheme);
let url = if PROXY_DEV_SERVER && is_local_network_url(&app_url) {
let url = if PROXY_DEV_SERVER
&& is_local_network_url(&app_url)
// only proxy the dev server when we're not using embedded assets
&& app_manager.assets.iter().next().is_none()
{
Cow::Owned(Url::parse("tauri://localhost").unwrap())
} else {
app_url
@@ -430,7 +434,12 @@ impl<R: Runtime> WebviewManager<R> {
let config_url = app_manager.get_url(pending.webview_attributes.use_https_scheme);
let is_app_url = config_url.make_relative(url).is_some();
let mut url = url.clone();
if is_app_url && PROXY_DEV_SERVER && is_local_network_url(&url) {
if is_app_url
&& PROXY_DEV_SERVER
&& is_local_network_url(&url)
// only proxy the dev server when we're not using embedded assets
&& app_manager.assets.iter().next().is_none()
{
Url::parse("tauri://localhost").unwrap()
} else {
url
@@ -440,7 +449,6 @@ impl<R: Runtime> WebviewManager<R> {
WebviewUrl::CustomProtocol(url) => url.clone(),
_ => unimplemented!(),
};
#[cfg(not(feature = "webview-data-url"))]
if url.scheme() == "data" {
return Err(crate::Error::InvalidWebviewUrl(

View File

@@ -72,8 +72,9 @@ fn get_response<R: Runtime>(
web_resource_request_handler: Option<&WebResourceRequestHandler>,
(url, response_cache): (&str, &Arc<Mutex<HashMap<String, CachedResponse>>>),
) -> Result<HttpResponse<Cow<'static, [u8]>>, Box<dyn std::error::Error>> {
let proxy_dev_server = PROXY_DEV_SERVER && manager.assets.iter().next().is_none();
// use the entire URI as we are going to proxy the request
let path = if PROXY_DEV_SERVER {
let path = if proxy_dev_server {
request.uri().to_string()
} else {
// ignore query string and fragment
@@ -97,7 +98,7 @@ fn get_response<R: Runtime>(
.add_configured_headers(manager.config.app.security.headers.as_ref())
.header("Access-Control-Allow-Origin", window_origin);
let mut response = if PROXY_DEV_SERVER && manager.assets.iter().count() == 0 {
let mut response = if proxy_dev_server {
let decoded_path = percent_encoding::percent_decode(path.as_bytes())
.decode_utf8_lossy()
.to_string();