From 62dbe0e1ca8b0fc4a0d5384948db6112cfaf91d2 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 7 Jun 2013 00:46:30 +0100 Subject: [PATCH] The default run method is now accepting the port from the SERVER_NAME. --- CHANGES | 2 ++ flask/app.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 87e4911b..5a87b701 100644 --- a/CHANGES +++ b/CHANGES @@ -71,6 +71,8 @@ Release date to be decided. - Flask now orders JSON keys by default to not trash HTTP caches due to different hash seeds between different workers. - Added `appcontext_pushed` and `appcontext_popped` signals. +- The builtin run method now takes the ``SERVER_NAME`` into account when + picking the default port to run on. Version 0.9 ----------- diff --git a/flask/app.py b/flask/app.py index 80e0bdb7..267c9c00 100644 --- a/flask/app.py +++ b/flask/app.py @@ -739,10 +739,15 @@ class Flask(_PackageBoundObject): won't catch any exceptions because there won't be any to catch. + .. versionchanged:: 0.10 + The default port is now picked from the ``SEVER_NAME`` variable. + :param host: the hostname to listen on. Set this to ``'0.0.0.0'`` to have the server available externally as well. Defaults to ``'127.0.0.1'``. - :param port: the port of the webserver. Defaults to ``5000``. + :param port: the port of the webserver. Defaults to ``5000`` or the + port defined in the ``SERVER_NAME`` config variable if + present. :param debug: if given, enable or disable debug mode. See :attr:`debug`. :param options: the options to be forwarded to the underlying @@ -754,7 +759,11 @@ class Flask(_PackageBoundObject): if host is None: host = '127.0.0.1' if port is None: - port = 5000 + server_name = self.config['SERVER_NAME'] + if server_name and ':' in server_name: + port = int(server_name.rsplit(':', 1)[1]) + else: + port = 5000 if debug is not None: self.debug = bool(debug) options.setdefault('use_reloader', self.debug)