Skip to content

Commit 234fef5

Browse files
authored
Merge pull request #10 from HoughIO/fix_websocket_over_https
update websocket uri to use wss if https is in the Server.public_url
2 parents ca88974 + aeb5911 commit 234fef5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/textual_serve/server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def __init__(
9393
if public_url is None:
9494
if self.port == 80:
9595
self.public_url = f"http://{self.host}"
96+
elif self.port == 443:
97+
self.public_url = f"https://{self.host}"
9698
else:
9799
self.public_url = f"http://{self.host}:{self.port}"
98100
else:
@@ -251,7 +253,11 @@ def get_url(route: str, **args) -> str:
251253
def get_websocket_url(route: str, **args) -> str:
252254
"""Get a URL with a websocket prefix."""
253255
url = get_url(route, **args)
254-
return "ws:" + url.split(":", 1)[1]
256+
257+
if self.public_url.startswith("https"):
258+
return "wss:" + url.split(":", 1)[1]
259+
else:
260+
return "ws:" + url.split(":", 1)[1]
255261

256262
context = {
257263
"font_size": font_size,

0 commit comments

Comments
 (0)