Skip to content

Commit

Permalink
Adds DASH and PORT env vars to run_server
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenMatsuda committed Mar 19, 2020
1 parent aa20bd4 commit 1bbe729
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- [#1134](https://github.com/plotly/dash/pull/1134) Allow `dash.run_server()` host and port parameters to be set with environment variables HOST & PORT, respectively

### Changed
- [#1145](https://github.com/plotly/dash/pull/1145) Update from React 16.8.6 to 16.13.0

Expand Down
21 changes: 18 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,8 @@ def delete_resource(resources):

def run_server(
self,
port=8050,
host=os.getenv("HOST", "127.0.0.1"),
port=os.getenv("PORT", "8050"),
debug=False,
dev_tools_ui=None,
dev_tools_props_check=None,
Expand All @@ -1860,7 +1861,12 @@ def run_server(
If a parameter can be set by an environment variable, that is listed
too. Values provided here take precedence over environment variables.
:param host: Host IP used to serve the application
env: ``HOST``
:type host: string
:param port: Port used to serve the application
env: ``PORT``
:type port: int
:param debug: Set Flask debug mode and enable dev tools.
Expand Down Expand Up @@ -1933,9 +1939,18 @@ def run_server(
dev_tools_prune_errors,
)

# Verify port value
try:
port = int(port)
assert port in range(1, 65536)
except Exception as e:
e.args = [
"Expecting an integer from 1 to 65535, found port={}".format(repr(port))
]
raise

if self._dev_tools.silence_routes_logging:
# Since it's silenced, the address doesn't show anymore.
host = flask_run_options.get("host", "127.0.0.1")
ssl_context = flask_run_options.get("ssl_context")
self.logger.info(
"Running on %s://%s:%s%s",
Expand All @@ -1955,4 +1970,4 @@ def run_server(

self.logger.info("Debugger PIN: %s", debugger_pin)

self.server.run(port=port, debug=debug, **flask_run_options)
self.server.run(host=host, port=port, debug=debug, **flask_run_options)

0 comments on commit 1bbe729

Please sign in to comment.