dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Fullstack v0.5.6: POST api and reverse proxy setup, complicated.

Open ThomasCartier opened this issue 1 year ago • 0 comments

Hi,

Feel free to convert to a feature request, bug I consider this an issue right now.

1. Controlling the appended value to the /api/ calls

Using the latest up to date stable Dioxus fullstack, after controlling the network exchanges between the client and the server, I noticed that every time the client does a request, the network packet looks like (excerpt from wireshark):

884 0.715949171 127.0.0.1 127.0.0.1 HTTP 679 POST /api/my_server_function4227210978949717125 HTTP/1.1 (application/x-www-form-urlencoded)

This is an issue when setting reverse proxies between the client and the axum server because it forces to discover the address and update the proxy configurations accordingly.

We should have an option for this that would acknowledge this possibility + a way not to append the unique numbers 4227210978949717125 by two ways:

  1. either by having the dev set the random number by himself :
#[server]
#[dioxus_tag = 123456]
pub(crate) async fn my_server_function()->Result<(), ServerError>{}

that would lead to 884 0.715949171 127.0.0.1 127.0.0.1 HTTP 679 POST /api/my_server_function#123456 HTTP/1.1 (application/x-www-form-urlencoded)

Cons: easy to forget. In case it's not present, it leads to issues if the apps on a same server have the same server name. Not great.

  1. give a random number while creating the app using dx new or init, and set it in the dioxus.toml:
[application]
unique_tag = "value generated by dx tool here" -> e.g "123456"

884 0.715949171 127.0.0.1 127.0.0.1 HTTP 679 POST /api/123456/my_server_function HTTP/1.1 (application/x-www-form-urlencoded)

This is better because nothing more has to be done on the dev side, no overlook. And this value can be modified by the dev.

Cons: if modifiable, that would imply some machinery to update the all the related components.

2. And an option to prepare for a reverse proxy in between in the dioxus.toml:

[proxy]
address = ["w.x.y.z", 443]

And an option for the axum server (port 8965 given arbitrarily):

[server]
address = ["a.b.c.d", 8965]

I know v6.x has a port and address dynamic configuration via the command line, but this is more comfortable when multiple people have to check the configuration.

That would give the address of the proxy so that the client makes the request there and settle the Axum server to its own address. This way, the dev can set the reverse proxy in between, which can be anything (leave it to the dev) and help checking the configuration in config files instead. The reverse proxy can then be acknowledged to send the request at the listening servers addresses that are listed in dioxus.toml (ssl termination, url rewrites anything, but that is out of focus of Dioxus).

Maybe there is some machinery that I somehow overlooked to make this work but this is the 2 issues/feature requests we are having.

If you have any other questions, please tell me!

ThomasCartier avatar Oct 23 '24 12:10 ThomasCartier