|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
import asyncio
|
|
|
import websockets
|
|
|
+import ssl
|
|
|
import json
|
|
|
import sys
|
|
|
import os
|
|
|
@@ -10,7 +11,6 @@ from routes import Routes
|
|
|
|
|
|
routes = Routes()
|
|
|
|
|
|
-
|
|
|
class UserInfoProtocol(websockets.BasicAuthWebSocketServerProtocol):
|
|
|
async def check_credentials(self, username, password):
|
|
|
all_users = routes.users()
|
|
|
@@ -32,10 +32,18 @@ async def handle(websocket):
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
+ ssl_context = None
|
|
|
+ pem = "/cert/live/beerlog.ddns.net/fullchain.pem"
|
|
|
+ key = "/cert/live/beerlog.ddns.net/privkey.pem"
|
|
|
+ if os.path.exists(pem):
|
|
|
+ print(f"Start with {pem}", file=sys.stderr)
|
|
|
+ ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
+ ssl_context.load_cert_chain(pem, keyfile=key)
|
|
|
+
|
|
|
port = os.environ.get("BEERLOG_PORT", 8000)
|
|
|
host = os.environ.get("BEERLOG_HOST", "0.0.0.0")
|
|
|
print(f"Start on {host}:{port}", file=sys.stderr)
|
|
|
- async with websockets.serve(handle, host, port, create_protocol=UserInfoProtocol):
|
|
|
+ async with websockets.serve(handle, host, port, ssl=ssl_context, create_protocol=UserInfoProtocol):
|
|
|
await asyncio.Future()
|
|
|
|
|
|
|