Skip to content

Commit 62dbe0e

Browse files
committed
The default run method is now accepting the port from the SERVER_NAME.
1 parent 05479eb commit 62dbe0e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Release date to be decided.
7171
- Flask now orders JSON keys by default to not trash HTTP caches due to
7272
different hash seeds between different workers.
7373
- Added `appcontext_pushed` and `appcontext_popped` signals.
74+
- The builtin run method now takes the ``SERVER_NAME`` into account when
75+
picking the default port to run on.
7476

7577
Version 0.9
7678
-----------

flask/app.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,15 @@ def run(self, host=None, port=None, debug=None, **options):
739739
won't catch any exceptions because there won't be any to
740740
catch.
741741
742+
.. versionchanged:: 0.10
743+
The default port is now picked from the ``SEVER_NAME`` variable.
744+
742745
:param host: the hostname to listen on. Set this to ``'0.0.0.0'`` to
743746
have the server available externally as well. Defaults to
744747
``'127.0.0.1'``.
745-
:param port: the port of the webserver. Defaults to ``5000``.
748+
:param port: the port of the webserver. Defaults to ``5000`` or the
749+
port defined in the ``SERVER_NAME`` config variable if
750+
present.
746751
:param debug: if given, enable or disable debug mode.
747752
See :attr:`debug`.
748753
:param options: the options to be forwarded to the underlying
@@ -754,7 +759,11 @@ def run(self, host=None, port=None, debug=None, **options):
754759
if host is None:
755760
host = '127.0.0.1'
756761
if port is None:
757-
port = 5000
762+
server_name = self.config['SERVER_NAME']
763+
if server_name and ':' in server_name:
764+
port = int(server_name.rsplit(':', 1)[1])
765+
else:
766+
port = 5000
758767
if debug is not None:
759768
self.debug = bool(debug)
760769
options.setdefault('use_reloader', self.debug)

0 commit comments

Comments
 (0)