Assuming the SERVER_NAME config variable is configured as '0.0.0.0:5555':
- Calling app.run(host=None, port=None) results in flask running on http://127.0.0.1:5555/
- Calling app.run(host='127.0.0.1', port=5000) results in flask running on http://127.0.0.1:5000/
In both cases the SERVER_NAME config variable does not correspond to where flask is actually running.
The host and port parameters in app.run() must of course take precedence, but should be set according to the SERVER_NAME config variable if present.
The current implementation in app.run():
if host is None:
host = '127.0.0.1'
if port is None:
server_name = self.config['SERVER_NAME']
if server_name and ':' in server_name:
port = int(server_name.rsplit(':', 1)[1])
else:
port = 5000
Could be replaced by the following:
_host = '127.0.0.1'
_port = 5000
servername = self.config['SERVER_NAME']
if server_name:
if server_name and ':' in server_name:
_host, _port = servername.split(':', 1)
if host is None:
host = _host
if port is None:
port = _port
The following can be used to make sure the SERVER_NAME config variable corresponds to where flask is actually running:
if servername:
self.config['SERVER_NAME'] = host + ':' + port
Assuming the SERVER_NAME config variable is configured as '0.0.0.0:5555':
In both cases the SERVER_NAME config variable does not correspond to where flask is actually running.
The host and port parameters in app.run() must of course take precedence, but should be set according to the SERVER_NAME config variable if present.
The current implementation in app.run():
Could be replaced by the following:
The following can be used to make sure the SERVER_NAME config variable corresponds to where flask is actually running: