|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import asyncio |
4 | | - |
5 | 4 | import logging |
6 | 5 | import os |
7 | | -from pathlib import Path |
8 | 6 | import signal |
9 | 7 | import sys |
10 | | - |
| 8 | +from importlib.metadata import version |
| 9 | +from pathlib import Path |
11 | 10 | from typing import Any |
12 | 11 |
|
13 | 12 | import aiohttp_jinja2 |
14 | | -from aiohttp import web |
15 | | -from aiohttp import WSMsgType |
16 | | -from aiohttp.web_runner import GracefulExit |
17 | 13 | import jinja2 |
18 | | - |
19 | | -from importlib.metadata import version |
20 | | - |
| 14 | +from aiohttp import WSMsgType, web |
| 15 | +from aiohttp.web_runner import GracefulExit |
21 | 16 | from rich import print |
22 | 17 | from rich.console import Console |
23 | | -from rich.logging import RichHandler |
24 | 18 | from rich.highlighter import RegexHighlighter |
| 19 | +from rich.logging import RichHandler |
25 | 20 |
|
26 | 21 | from .app_service import AppService |
27 | 22 |
|
|
30 | 25 | LOGO = r"""[bold magenta]___ ____ _ _ ___ _ _ ____ _ ____ ____ ____ _ _ ____ |
31 | 26 | | |___ \/ | | | |__| | __ [__ |___ |__/ | | |___ |
32 | 27 | | |___ _/\_ | |__| | | |___ ___] |___ | \ \/ |___ [not bold]VVVVV |
33 | | -""".replace("VVVVV", f"v{version('textual-serve')}") |
| 28 | +""".replace( |
| 29 | + "VVVVV", f"v{version('textual-serve')}" |
| 30 | +) |
34 | 31 |
|
35 | 32 |
|
36 | 33 | WINDOWS = sys.platform == "WINDOWS" |
@@ -92,6 +89,8 @@ def __init__( |
92 | 89 | if public_url is None: |
93 | 90 | if self.port == 80: |
94 | 91 | self.public_url = f"http://{self.host}" |
| 92 | + elif self.port == 443: |
| 93 | + self.public_url = f"https://{self.host}" |
95 | 94 | else: |
96 | 95 | self.public_url = f"http://{self.host}:{self.port}" |
97 | 96 | else: |
@@ -214,7 +213,11 @@ def get_url(route: str, **args) -> str: |
214 | 213 | def get_websocket_url(route: str, **args) -> str: |
215 | 214 | """Get a URL with a websocket prefix.""" |
216 | 215 | url = get_url(route, **args) |
217 | | - return "ws:" + url.split(":", 1)[1] |
| 216 | + |
| 217 | + if self.public_url.startswith("https"): |
| 218 | + return "wss:" + url.split(":", 1)[1] |
| 219 | + else: |
| 220 | + return "ws:" + url.split(":", 1)[1] |
218 | 221 |
|
219 | 222 | context = { |
220 | 223 | "font_size": font_size, |
|
0 commit comments