Split runner entrypoint from default local runner.
This commit is contained in:
parent
4434517c54
commit
ed3b67bdb9
2 changed files with 55 additions and 27 deletions
8
frontends/etiquette_flask/etiquette_flask_entrypoint.py
Normal file
8
frontends/etiquette_flask/etiquette_flask_entrypoint.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import sys
|
||||
|
||||
import etiquette_flask
|
||||
import werkzeug.contrib.fixers
|
||||
|
||||
etiquette_flask.site.wsgi_app = werkzeug.contrib.fixers.ProxyFix(etiquette_flask.site.wsgi_app)
|
||||
|
||||
site = etiquette_flask.site
|
|
@ -1,5 +1,4 @@
|
|||
import gevent.monkey
|
||||
gevent.monkey.patch_all()
|
||||
import gevent.monkey; gevent.monkey.patch_all()
|
||||
|
||||
import logging
|
||||
handler = logging.StreamHandler()
|
||||
|
@ -7,38 +6,59 @@ log_format = '{levelname}:etiquette.{module}.{funcName}: {message}'
|
|||
handler.setFormatter(logging.Formatter(log_format, style='{'))
|
||||
logging.getLogger().addHandler(handler)
|
||||
|
||||
import etiquette_flask
|
||||
import gevent.pywsgi
|
||||
import gevent.wsgi
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import etiquette_flask_entrypoint
|
||||
|
||||
import werkzeug.contrib.fixers
|
||||
etiquette_flask.site.wsgi_app = werkzeug.contrib.fixers.ProxyFix(etiquette_flask.site.wsgi_app)
|
||||
site = etiquette_flask_entrypoint.site
|
||||
|
||||
def run(port=None, use_https=None):
|
||||
if port is None:
|
||||
port = 5000
|
||||
else:
|
||||
port = int(port)
|
||||
|
||||
if len(sys.argv) >= 2:
|
||||
port = int(sys.argv[1])
|
||||
else:
|
||||
port = 5000
|
||||
if use_https is None:
|
||||
use_https = port == 443
|
||||
|
||||
use_https = (port == 443) or ('--https' in sys.argv)
|
||||
if use_https:
|
||||
http = gevent.pywsgi.WSGIServer(
|
||||
listener=('0.0.0.0', port),
|
||||
application=etiquette_flask.site,
|
||||
keyfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.key',
|
||||
certfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.crt',
|
||||
)
|
||||
else:
|
||||
http = gevent.pywsgi.WSGIServer(
|
||||
listener=('0.0.0.0', port),
|
||||
application=etiquette_flask.site,
|
||||
)
|
||||
if use_https:
|
||||
http = gevent.pywsgi.WSGIServer(
|
||||
listener=('0.0.0.0', port),
|
||||
application=site,
|
||||
keyfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.key',
|
||||
certfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.crt',
|
||||
)
|
||||
else:
|
||||
http = gevent.pywsgi.WSGIServer(
|
||||
listener=('0.0.0.0', port),
|
||||
application=site,
|
||||
)
|
||||
|
||||
message = f'Starting server on port {port}'
|
||||
if use_https:
|
||||
message += ' (https)'
|
||||
print(message)
|
||||
try:
|
||||
http.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
return 0
|
||||
|
||||
message = 'Starting server on port %d' % port
|
||||
if use_https:
|
||||
message += ' (https)'
|
||||
print(message)
|
||||
http.serve_forever()
|
||||
def run_argparse(args):
|
||||
return run(port=args.port, use_https=args.use_https)
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument(dest='port', nargs='?', default=None)
|
||||
parser.add_argument('--https', dest='use_https', action='store_true', default=None)
|
||||
parser.set_defaults(func=run_argparse)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
args.func(args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
|
|
Loading…
Reference in a new issue