summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2025-01-06 02:35:56 +0100
committererdgeist <erdgeist@erdgeist.org>2025-01-06 02:35:56 +0100
commit3696c9bfdb7a813419c8a53362260d59118f318b (patch)
treed9a4dc1c4f46026efdd6759656000e1779c9d10b
parentcd949628c403d42a3cf58333a8b752f7b186fa81 (diff)
Make websocket address configurable
-rw-r--r--config.json2
-rw-r--r--fullnarp.py11
2 files changed, 9 insertions, 4 deletions
diff --git a/config.json b/config.json
index 1ba9ca3..b976591 100644
--- a/config.json
+++ b/config.json
@@ -2,6 +2,8 @@
2 "server-name": "halfnarp.events.ccc.de", 2 "server-name": "halfnarp.events.ccc.de",
3 "host": "127.0.0.1", 3 "host": "127.0.0.1",
4 "port": 5023, 4 "port": 5023,
5 "websocket-host": "localhost",
6 "websocket-port": "5042",
5 "database-uri": "postgresql://halfnarp@localhost:5432/halfnarp", 7 "database-uri": "postgresql://halfnarp@localhost:5432/halfnarp",
6 "pretalx-url": "https://cfp.example.de/", 8 "pretalx-url": "https://cfp.example.de/",
7 "pretalx-token": "<YOUR API KEY HERE>", 9 "pretalx-token": "<YOUR API KEY HERE>",
diff --git a/fullnarp.py b/fullnarp.py
index 71aa5f2..3a1262e 100644
--- a/fullnarp.py
+++ b/fullnarp.py
@@ -19,7 +19,7 @@ This is best served by an nginx block that should look a bit like this:
19 } 19 }
20 20
21 location /fullnarp/ws/ { 21 location /fullnarp/ws/ {
22 proxy_pass http://127.0.0.1:5009; 22 proxy_pass http://127.0.0.1:5042;
23 proxy_http_version 1.1; 23 proxy_http_version 1.1;
24 proxy_set_header Upgrade $http_upgrade; 24 proxy_set_header Upgrade $http_upgrade;
25 proxy_set_header Connection 'upgrade'; 25 proxy_set_header Connection 'upgrade';
@@ -206,7 +206,7 @@ async def main():
206 206
207 DATABASE_URL = config.get("database-uri", "sqlite:///test.db") 207 DATABASE_URL = config.get("database-uri", "sqlite:///test.db")
208 208
209 print("Connecting to " + DATABASE_URL) 209 print(f"Connecting to {DATABASE_URL}")
210 engine = create_engine(DATABASE_URL, echo=False) 210 engine = create_engine(DATABASE_URL, echo=False)
211 SessionLocal = sessionmaker(bind=engine) 211 SessionLocal = sessionmaker(bind=engine)
212 Base.metadata.create_all(bind=engine) 212 Base.metadata.create_all(bind=engine)
@@ -225,8 +225,11 @@ async def main():
225 current_version = {} 225 current_version = {}
226 newest_version = 0 226 newest_version = 0
227 227
228 async with websockets.serve(handle_client, "localhost", 22378): 228 ws_host = config.get("websocket-host", "localhost")
229 print("WebSocket server started on ws://localhost:22378") 229 ws_port = config.get("websocket-port", 5042)
230
231 async with websockets.serve(handle_client, ws_host, ws_port):
232 print(f"WebSocket server started on ws://{ws_host}:{ws_port}")
230 await asyncio.Future() # Run forever 233 await asyncio.Future() # Run forever
231 234
232 235