-
-
Notifications
You must be signed in to change notification settings - Fork 902
Description
First Check
- I added a very descriptive title here.
- This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
- I used the GitHub search to find a similar issue and came up empty.
Example Code
from nicegui import ui
ui.run(
port=8443,
native=True
ssl_certfile="<path_to_certfile>",
ssl_keyfile="<path_to_keyfile>",
)Description
When using ssl_certfile and ssl_keyfile in conjunction with native=True NiceGUI passes in the wrong protocol (http) to the native PyWebView window. This launches the browser window, but it launches with the http protocol, and because it's a native window, there is no way to manually correct this, resulting in a broken application that doesn't load (protocol error). The expected behavior is that the protocol URL is updated to https when passing in SSL values, directing the browser window to the correct protocol URL. The source of the issue is not that SSL is not used, but rather that the URL is not updated to reflect HTTPS.
The correct protocol is defined here:
Lines 187 to 190 in 26765aa
| if kwargs.get('ssl_certfile') and kwargs.get('ssl_keyfile'): | |
| protocol = 'https' | |
| else: | |
| protocol = 'http' |
Yet it is not used here:
Line 180 in 26765aa
| native_module.activate(native_host, port, title, width, height, fullscreen, frameless) |
and here
nicegui/nicegui/native/native_mode.py
Line 37 in 26765aa
| 'url': f'http://{host}:{port}', |
Solution:
-
The definition should be moved up a couple of lines before its (and passed in) use here:
Line 180 in 26765aa
native_module.activate(native_host, port, title, width, height, fullscreen, frameless) -
The function definition should be updated to take a
protocol
nicegui/nicegui/native/native_mode.py
Line 98 in 26765aa
def activate(host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool) -> None:
and here
nicegui/nicegui/native/native_mode.py
Line 98 in 26765aa
def activate(host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool) -> None:
and here
nicegui/nicegui/native/native_mode.py
Line 30 in 26765aa
host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool,
and lastly it should be chanched from"http://...to"{protocol}://...here
nicegui/nicegui/native/native_mode.py
Line 37 in 26765aa
'url': f'http://{host}:{port}',
It is correctly used here:
Line 26
in
26765aa
urls = [(f'{protocol}://{ip}:{port}' if port != '80' else f'{protocol}://{ip}') for ip in sorted_ips]
Line 26 in 26765aa
| urls = [(f'{protocol}://{ip}:{port}' if port != '80' else f'{protocol}://{ip}') for ip in sorted_ips] |
note
Fixing this issue would require to update two function signature definitions to pass in protocol:
nicegui/nicegui/native/native_mode.py
Line 30 in 26765aa
| host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool, |
nicegui/nicegui/native/native_mode.py
Line 98 in 26765aa
| def activate(host: str, port: int, title: str, width: int, height: int, fullscreen: bool, frameless: bool) -> None: |
NiceGUI Version
2.11.1
Python Version
3.12.3
Browser
Other
Operating System
Windows
Additional Context
No response