|
|
@ -20,23 +20,23 @@ def main( bind_addr, force_init_delay, flask_debug ): |
|
|
|
|
|
|
|
|
|
|
|
# initialize |
|
|
|
# initialize |
|
|
|
from vasl_templates.webapp import app |
|
|
|
from vasl_templates.webapp import app |
|
|
|
port = None |
|
|
|
flask_port = None |
|
|
|
if bind_addr: |
|
|
|
if bind_addr: |
|
|
|
words = bind_addr.split( ":" ) |
|
|
|
words = bind_addr.split( ":" ) |
|
|
|
host = words[0] |
|
|
|
flask_host = words[0] |
|
|
|
if len(words) > 1: |
|
|
|
if len(words) > 1: |
|
|
|
port = words[1] |
|
|
|
flask_port = words[1] |
|
|
|
else: |
|
|
|
else: |
|
|
|
host = app.config.get( "FLASK_HOST", "localhost" ) |
|
|
|
flask_host = app.config.get( "FLASK_HOST", "localhost" ) |
|
|
|
if not port: |
|
|
|
if not flask_port: |
|
|
|
port = app.config.get( "FLASK_PORT_NO" ) |
|
|
|
flask_port = app.config.get( "FLASK_PORT_NO" ) |
|
|
|
if not flask_debug: |
|
|
|
if not flask_debug: |
|
|
|
flask_debug = app.config.get( "FLASK_DEBUG", False ) |
|
|
|
flask_debug = app.config.get( "FLASK_DEBUG", False ) |
|
|
|
|
|
|
|
|
|
|
|
# validate the configuration |
|
|
|
# validate the configuration |
|
|
|
if not host: |
|
|
|
if not flask_host: |
|
|
|
raise RuntimeError( "The server host was not set." ) |
|
|
|
raise RuntimeError( "The server host was not set." ) |
|
|
|
if not port: |
|
|
|
if not flask_port: |
|
|
|
raise RuntimeError( "The server port was not set." ) |
|
|
|
raise RuntimeError( "The server port was not set." ) |
|
|
|
|
|
|
|
|
|
|
|
# monitor extra files for changes |
|
|
|
# monitor extra files for changes |
|
|
@ -61,15 +61,30 @@ def main( bind_addr, force_init_delay, flask_debug ): |
|
|
|
# it's useful to send a request (any request), since this will trigger "first request" initialization |
|
|
|
# it's useful to send a request (any request), since this will trigger "first request" initialization |
|
|
|
# (in particular, starting the download thread). |
|
|
|
# (in particular, starting the download thread). |
|
|
|
time.sleep( force_init_delay ) |
|
|
|
time.sleep( force_init_delay ) |
|
|
|
url = "http://{}:{}/ping".format( host, port ) |
|
|
|
url = "http://{}:{}/ping".format( flask_host, flask_port ) |
|
|
|
with urllib.request.urlopen( url ) as resp: |
|
|
|
with urllib.request.urlopen( url ) as resp: |
|
|
|
_ = resp.read() |
|
|
|
_ = resp.read() |
|
|
|
threading.Thread( target=_start_server, daemon=True ).start() |
|
|
|
threading.Thread( target=_start_server, daemon=True ).start() |
|
|
|
|
|
|
|
|
|
|
|
# run the server |
|
|
|
# run the server |
|
|
|
app.run( host=host, port=port, debug=flask_debug, |
|
|
|
if flask_debug: |
|
|
|
extra_files = extra_files |
|
|
|
# NOTE: It's useful to run the webapp using the Flask development server, since it will |
|
|
|
|
|
|
|
# automatically reload itself when the source files change. |
|
|
|
|
|
|
|
app.run( |
|
|
|
|
|
|
|
host=flask_host, port=flask_port, |
|
|
|
|
|
|
|
debug=flask_debug, |
|
|
|
|
|
|
|
extra_files=extra_files |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
import waitress |
|
|
|
|
|
|
|
# FUDGE! Browsers tend to send a max. of 6-8 concurrent requests per server, so we increase |
|
|
|
|
|
|
|
# the number of worker threads to avoid task queue warnings :-/ |
|
|
|
|
|
|
|
nthreads = app.config.get( "WAITRESS_THREADS", 8 ) |
|
|
|
|
|
|
|
waitress.serve( app, |
|
|
|
|
|
|
|
host=flask_host, port=flask_port, |
|
|
|
|
|
|
|
threads=nthreads |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
|
|
|
# --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|