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
http server configuration has wrong hostname and port if they are set through cli ( -H hostname -p port ) #2755
Comments
The issue you're hitting is that you're attempting to print the hostname and port before Vapor has read the command line arguments. Vapor only reads these parameters when it starts ups which is after you call configure |
I tried to log configuration hostname and port inside a route handler and the result is the same as I reported before.
Did you actually try to see if you get the same behaviour as me? |
Your observation seems to be on spot, and I see something in the code that explains it. These lines in HTTPServer.swift operate on a copy of the configuration, and the original |
@vzsg Yes that is true, I looked at the code and to my surprise it seems like that has been done on purpose. As you can see here (Application+HTTP+Server.swift) It looks like this was known and in fact, as you reported, the address' override is done on a copy which is used just to start the server and then is actually thrown away. Unfortunately right now I have not enough knowledge of vapor to be able to make some good modification to fix this bug. Furthermore It doesn't look like a simple thing to do. But still I would love to contribute to this amazing framework. Feel free to ask for any help :) |
Just put a PR up to fix this |
Hey everyone, I've just faced this exact same issue recently, I'm using version |
We can update application.storage from within HTTPServer, this way we can keep any changes that happen to the configuration internally up-to-date with the application storage
If we change HTTPServer.Configuration to be a reference type rather than a value type we can then pass this reference into HTTPServer from the server extension service and then any changes done inside HTTPServer are automatically reflected on the storage in the server extension service
@rkreutz |
hey, so you can actually do |
* Fixing issue #2755: updating storage inside HTTPServer We can update application.storage from within HTTPServer, this way we can keep any changes that happen to the configuration internally up-to-date with the application storage * Adding Unit Tests Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
Describe the bug
It looks like that even if the application has been started setting custom hostname and port via CLI, the hostname and port properties of app.http.server.configuration return the default 127.0.0.1:8080.
Some other properties may be incorrect too, I didn't test those.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I think that configuration should reflect the real hostname and port that the server is running on.
Environment
Additional context
If hostname and port are changed programmatically in configure.swift configure method then they are successfully set to the correct values.
The text was updated successfully, but these errors were encountered: