Mayo commited on
Commit
ba359ca
·
unverified ·
1 Parent(s): f6f41e4

fix: prefer 4000 port

Browse files
Files changed (2) hide show
  1. koharu/src/app.rs +15 -3
  2. ui/next.config.ts +1 -1
koharu/src/app.rs CHANGED
@@ -91,10 +91,22 @@ pub async fn run() -> Result<()> {
91
  #[cfg(target_os = "windows")]
92
  crate::windows::register_khr().ok();
93
 
94
- let default_port = if cfg!(debug_assertions) { 9999 } else { 0 };
95
  let bind_host = cli.host.as_deref().unwrap_or("127.0.0.1");
96
- let bind_port = cli.port.unwrap_or(default_port);
97
- let listener: TcpListener = TcpListener::bind((bind_host, bind_port)).await?;
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  let port = listener.local_addr()?.port();
99
  tracing::info!(port, "starting server");
100
 
 
91
  #[cfg(target_os = "windows")]
92
  crate::windows::register_khr().ok();
93
 
 
94
  let bind_host = cli.host.as_deref().unwrap_or("127.0.0.1");
95
+ let bind_port = cli.port.unwrap_or(4000);
96
+ let listener: TcpListener = if cfg!(debug_assertions) || cli.port.is_some() {
97
+ TcpListener::bind((bind_host, bind_port)).await?
98
+ } else {
99
+ let mut port = bind_port;
100
+ loop {
101
+ match TcpListener::bind((bind_host, port)).await {
102
+ Ok(listener) => break listener,
103
+ Err(err) if err.kind() == std::io::ErrorKind::AddrInUse && port < u16::MAX => {
104
+ port += 1;
105
+ }
106
+ Err(err) => return Err(err.into()),
107
+ }
108
+ }
109
+ };
110
  let port = listener.local_addr()?.port();
111
  tracing::info!(port, "starting server");
112
 
ui/next.config.ts CHANGED
@@ -25,7 +25,7 @@ const nextConfig: NextConfig = {
25
  return [
26
  {
27
  source: '/api/v1/:path*',
28
- destination: 'http://127.0.0.1:9999/api/v1/:path*',
29
  },
30
  ]
31
  },
 
25
  return [
26
  {
27
  source: '/api/v1/:path*',
28
+ destination: 'http://127.0.0.1:4000/api/v1/:path*',
29
  },
30
  ]
31
  },