dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Assigning a port number when using `dx serve --port [number]` on fullstack is not respected.

Open alice-werefox opened this issue 1 year ago • 2 comments

Problem

I'm attempting to serve my app using the fullstack feature, and I cannot get it to run on this machine without changing the port number it's listening on.

Steps To Reproduce

Steps to reproduce the behavior:

  • Set the platform to "fullstack"
  • Attempt to serve using the dioxus cli command dx serve --port [number]

Expected behavior

Dioxus will run and listen on the port number given in --port [number]

Screenshots

(It's difficult to show the command before running it, so I've provided a screenshot where I ran it, then closed the process and went back in my shell history to that command) image

Environment:

  • Dioxus version: 0.5.1
  • Rust version: 1.77.2
  • OS info: Cachy OS (Arch linux)
  • App platform: fullstack

Questionnaire

  • [x] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [ ] I don't have time to fix this right now, but maybe later

alice-werefox avatar May 01 '24 06:05 alice-werefox

Fullstack builds a separate server binary that renders the app on the server and serves static files. That server uses a default port of 8080 that can be changed in the fullstack config.

The dioxus-cli currently only forwards information in the dioxus.toml config to applications with the DIOXUS_CONFIG environment variable (here). We need to also forward some CLI args like --port

If you are interested in working on this issue, we could introduce a new struct in the cli-config library that has runtime settings for dioxus like --port. When we run the CLI, we could set the environment variable like DIOXUS_ARGUMENTS and then read it inside the fullstack server to provide a better default port value

ealmloff avatar May 01 '24 13:05 ealmloff

Thank you for the feedback!

I can confirm, from referencing the axum-router example, and the Dioxus fullstack config source code, I was able to create this snippet:

    let cfg = server_only!(
        dioxus::fullstack::Config::new().addr(std::net::SocketAddr::from(([0, 0, 0, 0], 8234)))
    );

    LaunchBuilder::fullstack()
        .with_cfg(cfg)
        .launch(info_app::DioxusApp);

This will result in a built binary that will listen on 0.0.0.0:8234, which resolves the issue.

I would request that there be more consistent documentation on this, if possible. It's at the best slightly confusing to imply that fullstack's listen parameters can be changed with a --port flag. There does not seem to be any mention of how to do this, so without knowing where to look, and what to look for, it would be reasonable to assume someone in a similar position may just assume it isn't possible altogether.

Fullstack builds a separate server binary that renders the app on the server and serves static files. That server uses a default port of 8080 that can be changed in the fullstack config.

At the very least, it would be good to mention this somewhere, and possibly take code snippets from the examples to show how you would change it.

If you are interested in working on this issue, we could introduce a new struct in the cli-config library that has runtime settings for dioxus like --port. When we run the CLI, we could set the environment variable like DIOXUS_ARGUMENTS and then read it inside the fullstack server to provide a better default port value

I have no problem with taking a look at this myself, but I am going to be a little busy the next week or so. I think that one of two (or both) solutions would be the best option moving forward with this:

  • Make it clear where an addr and/or port value could be added to an existing Dioxus.toml to be forwarded to a compiled binary in fullstack
  • Add a cli flag as you suggested that would do the same

Both approaches I think have decent merit, and achieve the same goal.

alice-werefox avatar May 01 '24 20:05 alice-werefox