fix python -m method of running
This commit is contained in:
parent
7e3496f8aa
commit
8cf7dce33f
|
@ -28,10 +28,13 @@ if __name__ == "__main__":
|
||||||
raise ValueError("Module is not a Sanic app, it is a {}. "
|
raise ValueError("Module is not a Sanic app, it is a {}. "
|
||||||
"Perhaps you meant {}.app?"
|
"Perhaps you meant {}.app?"
|
||||||
.format(type(app).__name__, args.module))
|
.format(type(app).__name__, args.module))
|
||||||
|
if args.cert is not None or args.key is not None:
|
||||||
|
ssl = {'cert': args.cert, 'key': args.key}
|
||||||
|
else:
|
||||||
|
ssl = None
|
||||||
|
|
||||||
app.run(host=args.host, port=args.port,
|
app.run(host=args.host, port=args.port,
|
||||||
workers=args.workers, debug=args.debug,
|
workers=args.workers, debug=args.debug, ssl=ssl)
|
||||||
cert=args.cert, key=args.key)
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
log.error("No module named {} found.\n"
|
log.error("No module named {} found.\n"
|
||||||
" Example File: project/sanic_server.py -> app\n"
|
" Example File: project/sanic_server.py -> app\n"
|
||||||
|
|
|
@ -7,7 +7,7 @@ from functools import partial
|
||||||
from inspect import isawaitable, stack, getmodulename
|
from inspect import isawaitable, stack, getmodulename
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from urllib.parse import urlencode, urlunparse
|
from urllib.parse import urlencode, urlunparse
|
||||||
from ssl import create_default_context
|
from ssl import create_default_context, Purpose
|
||||||
|
|
||||||
from sanic.config import Config
|
from sanic.config import Config
|
||||||
from sanic.constants import HTTP_METHODS
|
from sanic.constants import HTTP_METHODS
|
||||||
|
@ -635,9 +635,9 @@ class Sanic:
|
||||||
# try common aliaseses
|
# try common aliaseses
|
||||||
cert = ssl.get('cert') or ssl.get('certificate')
|
cert = ssl.get('cert') or ssl.get('certificate')
|
||||||
key = ssl.get('key') or ssl.get('keyfile')
|
key = ssl.get('key') or ssl.get('keyfile')
|
||||||
if not cert and key:
|
if cert is None or key is None:
|
||||||
raise ValueError("SSLContext or certificate and key required.")
|
raise ValueError("SSLContext or certificate and key required.")
|
||||||
context = create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
|
context = create_default_context(purpose=Purpose.CLIENT_AUTH)
|
||||||
context.load_cert_chain(cert, keyfile=key)
|
context.load_cert_chain(cert, keyfile=key)
|
||||||
ssl = context
|
ssl = context
|
||||||
if stop_event is not None:
|
if stop_event is not None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user