etiquette/frontends/etiquette_flask/etiquette_flask_launch.py

45 lines
1.1 KiB
Python
Raw Normal View History

2016-11-27 09:06:11 +00:00
import gevent.monkey
gevent.monkey.patch_all()
2016-09-18 08:33:46 +00:00
import logging
handler = logging.StreamHandler()
log_format = '{levelname}:etiquette.{module}.{funcName}: {message}'
handler.setFormatter(logging.Formatter(log_format, style='{'))
logging.getLogger().addHandler(handler)
import etiquette_flask
2016-09-18 08:33:46 +00:00
import gevent.pywsgi
import gevent.wsgi
import sys
import werkzeug.contrib.fixers
etiquette_flask.site.wsgi_app = werkzeug.contrib.fixers.ProxyFix(etiquette_flask.site.wsgi_app)
2018-04-15 08:00:37 +00:00
if len(sys.argv) >= 2:
2016-09-18 08:33:46 +00:00
port = int(sys.argv[1])
else:
port = 5000
2018-04-15 08:00:37 +00:00
use_https = (port == 443) or ('--https' in sys.argv)
if use_https:
2016-09-18 08:33:46 +00:00
http = gevent.pywsgi.WSGIServer(
2017-01-30 01:47:59 +00:00
listener=('0.0.0.0', port),
application=etiquette_flask.site,
2017-12-16 11:45:07 +00:00
keyfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.key',
certfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.crt',
2016-09-18 08:33:46 +00:00
)
else:
2016-11-27 09:06:11 +00:00
http = gevent.pywsgi.WSGIServer(
2017-01-30 01:47:59 +00:00
listener=('0.0.0.0', port),
application=etiquette_flask.site,
2016-11-27 09:06:11 +00:00
)
2016-09-18 08:33:46 +00:00
2018-04-15 08:00:37 +00:00
message = 'Starting server on port %d' % port
if use_https:
message += ' (https)'
print(message)
2016-12-16 11:27:39 +00:00
http.serve_forever()