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
|
import gevent.monkey; gevent.monkey.patch_all()
|
||||||
gevent.monkey.patch_all()
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
|
@ -7,38 +6,59 @@ log_format = '{levelname}:etiquette.{module}.{funcName}: {message}'
|
||||||
handler.setFormatter(logging.Formatter(log_format, style='{'))
|
handler.setFormatter(logging.Formatter(log_format, style='{'))
|
||||||
logging.getLogger().addHandler(handler)
|
logging.getLogger().addHandler(handler)
|
||||||
|
|
||||||
import etiquette_flask
|
|
||||||
import gevent.pywsgi
|
import gevent.pywsgi
|
||||||
import gevent.wsgi
|
import gevent.wsgi
|
||||||
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import etiquette_flask_entrypoint
|
||||||
|
|
||||||
import werkzeug.contrib.fixers
|
site = etiquette_flask_entrypoint.site
|
||||||
etiquette_flask.site.wsgi_app = werkzeug.contrib.fixers.ProxyFix(etiquette_flask.site.wsgi_app)
|
|
||||||
|
|
||||||
|
def run(port=None, use_https=None):
|
||||||
if len(sys.argv) >= 2:
|
if port is None:
|
||||||
port = int(sys.argv[1])
|
|
||||||
else:
|
|
||||||
port = 5000
|
port = 5000
|
||||||
|
else:
|
||||||
|
port = int(port)
|
||||||
|
|
||||||
use_https = (port == 443) or ('--https' in sys.argv)
|
if use_https is None:
|
||||||
if use_https:
|
use_https = port == 443
|
||||||
|
|
||||||
|
if use_https:
|
||||||
http = gevent.pywsgi.WSGIServer(
|
http = gevent.pywsgi.WSGIServer(
|
||||||
listener=('0.0.0.0', port),
|
listener=('0.0.0.0', port),
|
||||||
application=etiquette_flask.site,
|
application=site,
|
||||||
keyfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.key',
|
keyfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.key',
|
||||||
certfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.crt',
|
certfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.crt',
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
http = gevent.pywsgi.WSGIServer(
|
http = gevent.pywsgi.WSGIServer(
|
||||||
listener=('0.0.0.0', port),
|
listener=('0.0.0.0', port),
|
||||||
application=etiquette_flask.site,
|
application=site,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
message = f'Starting server on port {port}'
|
||||||
message = 'Starting server on port %d' % port
|
if use_https:
|
||||||
if use_https:
|
|
||||||
message += ' (https)'
|
message += ' (https)'
|
||||||
print(message)
|
print(message)
|
||||||
http.serve_forever()
|
try:
|
||||||
|
http.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
return 0
|
||||||
|
|
||||||
|
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