Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
alice-werefox opened this issue May 1, 2024 · 2 comments
Labels
bug Something isn't working cli Related to the dioxus-cli program fullstack related to the fullstack crate

Comments

@alice-werefox
Copy link

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

  • 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
@ealmloff ealmloff added cli Related to the dioxus-cli program fullstack related to the fullstack crate bug Something isn't working labels May 1, 2024
@ealmloff
Copy link
Member

ealmloff commented May 1, 2024

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

@alice-werefox
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli Related to the dioxus-cli program fullstack related to the fullstack crate
Projects
None yet
Development

No branches or pull requests

2 participants