Repository: DioxusLabs/dioxus (language: rust)

Issue:
"dx new" with fullstack, test: ServerFn Echo panics

### Discussed in https://github.com/DioxusLabs/dioxus/discussions/3673

<div type='discussions-op-text'>

<sup>Originally posted by **phkoester** January 30, 2025</sup>
Hello,

I'm totally new to Dioxus and am playing around with `dx new`. I noticed when I choose the fullstack option and launch my desktop app with `dx serve --platform desktop`, the echo server function doesn't work. I get the error 

```
16:37:40 [linux] thread 'main' panicked at src/components/echo.rs:18:65:
16:37:40 [linux] called `Result::unwrap()` on an `Err` value: Request("error sending request for url (http://127.0.0.1:43405/api/echo_server9820224038553403100)")
```

followed by a long stack trace. dx says "ServerFns at: http://127.0.0.1:8080". Is this a problem with the port?

When I run `dx run --platform desktop`, the echo demo works fine. But now I miss hot reloading, of course.

Steps to reproduce:

- use Dioxus CLI 0.6.2
- `dx new some_app`, choose fullstack
- Run the app with `dx serve --platform desktop`
- Type something below "ServerFn Echo"
- -> App panics</div>


Discussion / hints:
Hey did you find any work around? and by the way are you using wsl?
> Hey did you find any work around? and by the way are you using wsl?

For production builds you will always need to set the server url manually like the fullstack desktop example does [here](https://github.com/DioxusLabs/dioxus/blob/main/examples/fullstack-desktop/src/main.rs#L7)
Can confirm this happens on android as well and not just with a new project.
Also this: `    dioxus::fullstack::prelude::server_fn::client::set_server_url("http://127.0.0.1:8080");` didn't fix the issue for me.
It also didn't work for me with the real server URL.
A potential clue not sure it will help.... Old project with android and server functions still seems to be working and it seems to be independent of dioxus version being used.

Fix patch:
diff --git a/packages/dioxus/src/launch.rs b/packages/dioxus/src/launch.rs
index f8d997038b..efd431d16a 100644
--- a/packages/dioxus/src/launch.rs
+++ b/packages/dioxus/src/launch.rs
@@ -220,8 +220,10 @@ impl LaunchBuilder {
             use dioxus_fullstack::prelude::server_fn::client::{get_server_url, set_server_url};
             if get_server_url().is_empty() {
                 let serverurl = format!(
-                    "http://127.0.0.1:{}",
-                    std::env::var("PORT").unwrap_or_else(|_| "8080".to_string())
+                    "http://{}:{}",
+                    std::env::var("DIOXUS_DEVSERVER_IP")
+                        .unwrap_or_else(|_| "127.0.0.1".to_string()),
+                    std::env::var("DIOXUS_DEVSERVER_PORT").unwrap_or_else(|_| "8080".to_string())
                 )
                 .leak();
                 set_server_url(serverurl);


Test patch: