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

use SERVER_NAME to set host and port in app.run() #2152

Merged
merged 5 commits into from
Jan 17, 2017
Merged

Conversation

r0fls
Copy link
Contributor

@r0fls r0fls commented Jan 16, 2017

Addresses #2109

server_name = self.config.get("SERVER_NAME", None)
if server_name:
_host, _port = servername.split(':', 1)
host, port = host or _host, port or int(_port)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@davidism davidism changed the title use SERVER_CONFIG in app run() use SERVER_NAME to set host and port in app.run() Jan 16, 2017
_port = 5000
server_name = self.config.get("SERVER_NAME", None)
if server_name:
_host, _port = servername.split(':', 1)

This comment was marked as off-topic.

@r0fls
Copy link
Contributor Author

r0fls commented Jan 16, 2017

Yikes, thanks @jeffwidman. Any pointers on tests we could write to catch some of these types of situations?

_port = 5000
server_name = self.config.get("SERVER_NAME", None)
if server_name:
_host, _port = server_name.split(':', 1)

This comment was marked as off-topic.

This comment was marked as off-topic.

@davidism
Copy link
Member

davidism commented Jan 16, 2017

Is there a reason you didn't include the "set SEVER_NAME from run" part of the issue? It would require some more thought because you can't set the config to some values such as 0.0.0.0 (even though you shouldn't be running with that anyway).

@davidism
Copy link
Member

Posted this in the linked issue, but note that this won't and can't apply to the flask run command, which is the recommended way to run the dev server.

@jeffwidman
Copy link
Contributor

jeffwidman commented Jan 16, 2017

I haven't looked at the original issue in depth, but you got me curious on how to use partition properly... played with it and looks like something like this would properly handle the double fallback from app.run to SERVER_NAME to the built-in default. And it does it separately for both host and port values so you can specify one or the other or both:

_host = '127.0.0.1'
_port = 5000
server_name = self.config.get("SERVER_NAME")
if server_name:
    _sn_host, _, _sn_port = server_name.partition(':')
host = host or _sn_host or _host
port = int(port or _sn_port or _port)

@r0fls Feel free to use as much or as little of this as you want. I just really liked the clean/linear way your original implementation walked through the configs, so I'd hate to see your solution get too cluttered up...


_host = '127.0.0.1'
_port = 5000
server_name = self.config.get("SERVER_NAME", None)

This comment was marked as off-topic.

This comment was marked as off-topic.

server_name = self.config.get("SERVER_NAME")
if server_name:
sn_host, _, sn_port = server_name.partition(':')
host = host or sn_host or _host

This comment was marked as off-topic.

@r0fls
Copy link
Contributor Author

r0fls commented Jan 17, 2017

Should I rebase to 1 commit at this point, or does that not matter?

Copy link
Contributor

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

(Of course, I did say LGTM when it was broken, so take my review with a grain of salt)

@davidism
Copy link
Member

Not sure why the Python 2.6 tests started failing, but it seems unrelated.

@r0fls
Copy link
Contributor Author

r0fls commented Jan 17, 2017

Ya, it looks to be a message saying 2.6 is no longer supported or maintained by the core devs.

@untitaker
Copy link
Contributor

That is true but Flask still supports it. However, it appears that coverage.py no longer does.

@davidism davidism merged commit 1636a4c into pallets:master Jan 17, 2017
@untitaker
Copy link
Contributor

This needs a testcase and changelog.

davidism added a commit that referenced this pull request Jan 17, 2017
@davidism
Copy link
Member

Done.

Re: 2.6, it was fixed in Coverage earlier today, tests pass again. https://coverage.readthedocs.io/en/coverage-4.3.4/changes.html#version-4-3-4-2017-01-17

@john-bodley
Copy link

@davidism I was wondering whether the docstring for the host param should now reflect the updated behavior, i.e. similar to port,

... or the host defined in the SERVER_NAME config variable if present.

@jeffwidman
Copy link
Contributor

That is probably a good idea, do you want to open a PR?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants