Skip to content

Commit 7fec0f0

Browse files
fix(cli): use local ip addr for built-in server on mobile, closes #6454 (#6631)
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio> fix(cli): use local ip addr for built-in server on mobile, closes #6454
1 parent 29ee623 commit 7fec0f0

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'cli.rs': 'patch'
3+
'cli.js': 'patch'
4+
---
5+
6+
Use local ip address for built-in dev server on mobile.

tooling/cli/src/dev.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result<AppInterface> {
313313
use crate::helpers::web_dev_server::start_dev_server;
314314
if path.exists() {
315315
let path = path.canonicalize()?;
316-
let server_url = start_dev_server(path, options.port)?;
316+
let ip = if mobile {
317+
*local_ip_address(options.force_ip_prompt)
318+
} else {
319+
Ipv4Addr::new(127, 0, 0, 1).into()
320+
};
321+
let server_url = start_dev_server(path, ip, options.port)?;
317322
let server_url = format!("http://{server_url}");
318323
dev_path = AppUrl::Url(WindowUrl::External(server_url.parse().unwrap()));
319324

tooling/cli/src/helpers/web_dev_server.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use kuchiki::{traits::TendrilSink, NodeRef};
1414
use notify::RecursiveMode;
1515
use notify_debouncer_mini::new_debouncer;
1616
use std::{
17-
net::{Ipv4Addr, SocketAddr},
17+
net::{IpAddr, SocketAddr},
1818
path::{Path, PathBuf},
1919
sync::{mpsc::sync_channel, Arc},
2020
thread,
@@ -31,7 +31,11 @@ struct State {
3131
tx: Sender<()>,
3232
}
3333

34-
pub fn start_dev_server<P: AsRef<Path>>(path: P, port: Option<u16>) -> crate::Result<SocketAddr> {
34+
pub fn start_dev_server<P: AsRef<Path>>(
35+
path: P,
36+
ip: IpAddr,
37+
port: Option<u16>,
38+
) -> crate::Result<SocketAddr> {
3539
let serve_dir = path.as_ref().to_path_buf();
3640

3741
let (server_url_tx, server_url_rx) = std::sync::mpsc::channel();
@@ -79,7 +83,7 @@ pub fn start_dev_server<P: AsRef<Path>>(path: P, port: Option<u16>) -> crate::Re
7983
});
8084

8185
let (server, server_url) = loop {
82-
let server_url = SocketAddr::new(Ipv4Addr::new(127, 0, 0, 1).into(), port);
86+
let server_url = SocketAddr::new(ip, port);
8387
let server = Server::try_bind(&server_url);
8488

8589
if !auto_port {

0 commit comments

Comments
 (0)