diff --git a/.env.template b/.env.template index 194f82d..dbac04c 100644 --- a/.env.template +++ b/.env.template @@ -2,4 +2,5 @@ BLITZ_PORT=8100 DEFAULT_FILE="blitz.json" BLITZ_DB_TYPE="MEMORY" BLITZ_OPENAI_API_KEY="" -BLITZ_READ_ONLY=False \ No newline at end of file +BLITZ_READ_ONLY=False +BLITZ_BASE_URL="http://0.0.0.0:8100" \ No newline at end of file diff --git a/blitz/api/blitz_admin.py b/blitz/api/blitz_admin.py index aad0380..9f5be40 100644 --- a/blitz/api/blitz_admin.py +++ b/blitz/api/blitz_admin.py @@ -52,7 +52,7 @@ def __init__(self, blitz_app: "BlitzApp", settings: Settings = get_settings()) - Link( label="Go Back to Dashboard", icon="fa fa-link", - url=f"http://0.0.0.0:{settings.BLITZ_PORT}/dashboard/projects/{self.blitz_app.name}", + url=f"/dashboard/projects/{self.blitz_app.name}", ) ) self.admin.add_view(Link(label="GitHub", icon="fa-brands fa-github", url="https://github.com/Paperz-org/blitz")) diff --git a/blitz/cli/commands/start.py b/blitz/cli/commands/start.py index 82c7315..75df210 100644 --- a/blitz/cli/commands/start.py +++ b/blitz/cli/commands/start.py @@ -104,6 +104,8 @@ def start_blitz( reload_excludes=["*_migration.py", "migrations/*.py"], log_config=None, log_level="info", + proxy_headers=True, + forwarded_allow_ips="*", ) server = uvicorn.Server(server_config) ChangeReload(server_config, target=server.run, sockets=[server_config.bind_socket()]).run() diff --git a/blitz/settings.py b/blitz/settings.py index a616344..ddee464 100644 --- a/blitz/settings.py +++ b/blitz/settings.py @@ -22,6 +22,7 @@ class Config: BLITZ_DB_TYPE: DBTypes = DBTypes.SQLITE BLITZ_OPENAI_API_KEY: str = "" BLITZ_READ_ONLY: bool = False + BLITZ_BASE_URL: str = "http://0.0.0.0:8100" @lru_cache() diff --git a/blitz/ui/blitz_ui.py b/blitz/ui/blitz_ui.py index f066ee8..e7f64fa 100644 --- a/blitz/ui/blitz_ui.py +++ b/blitz/ui/blitz_ui.py @@ -16,7 +16,6 @@ def __init__(self, settings: Settings = get_settings()) -> None: self.preprompt = self._get_preprompt() self.settings = settings - self.localhost_url = f"http://0.0.0.0:{settings.BLITZ_PORT}" self.erd: str | None = None self._current_project: str | None = None self._current_app: BlitzApp | None = None diff --git a/blitz/ui/components/drawers/dashboard.py b/blitz/ui/components/drawers/dashboard.py index 588d196..8ce03ee 100644 --- a/blitz/ui/components/drawers/dashboard.py +++ b/blitz/ui/components/drawers/dashboard.py @@ -1,4 +1,5 @@ from blitz.ui.components.links.menu_link import MenuLink + from .base import BaseLeftDrawer @@ -10,7 +11,7 @@ def render(self) -> None: super().render() with self: MenuLink("Dashboard", f"/projects/{self.current_project}", "dashboard") - MenuLink("Admin", f"{self.blitz_ui.localhost_url}/admin/", "table_chart") + MenuLink("Admin", f"{self.blitz_ui.settings.BLITZ_BASE_URL}/admin/", "table_chart") MenuLink("Swagger", f"/projects/{self.current_project}/swagger", "api") MenuLink("Blitz File", f"/projects/{self.current_project}/blitz-file", "article") MenuLink("Diagram", f"/projects/{self.current_project}/diagram", "account_tree") diff --git a/blitz/ui/components/header.py b/blitz/ui/components/header.py index 1355d5a..9560c93 100644 --- a/blitz/ui/components/header.py +++ b/blitz/ui/components/header.py @@ -91,7 +91,7 @@ def render(self) -> None: HeaderElement(label="Blitz Dashboard", link=f"/projects/{self.blitz_ui.current_project}") with ItemsCenterContentCenterRow(classes="justify-between"): - with HeaderElement(label="Projects", link=f"{self.blitz_ui.localhost_url}/projects").disabled(): + with HeaderElement(label="Projects", link="/projects").disabled(): Tooltip("Multiple App management is coming soon") HeaderElement(label="GPT Builder", link="/gpt") HeaderElement("Documentation", "https://paperz-org.github.io/blitz/", new_tab=True) diff --git a/blitz/ui/components/status.py b/blitz/ui/components/status.py index 7516f55..0c53ab3 100644 --- a/blitz/ui/components/status.py +++ b/blitz/ui/components/status.py @@ -23,17 +23,19 @@ def __init__( classes: str = "", **kwargs: Any, ) -> None: + Timer(10.0, self._set_status) super().__init__(*args, props=props, classes=classes, **kwargs) async def _is_api_up(self) -> bool: async with AsyncClient() as client: - response = await client.get(f"{self.blitz_ui.localhost_url}/api") + response = await client.get(f"{self.blitz_ui.settings.BLITZ_BASE_URL}/api") return response.status_code == 200 async def _is_admin_up(self) -> bool: async with AsyncClient() as client: - response = await client.get(f"{self.blitz_ui.localhost_url}/admin/") + print(self.blitz_ui.settings.BLITZ_BASE_URL) + response = await client.get(f"{self.blitz_ui.settings.BLITZ_BASE_URL}/admin/") return response.status_code == 200 async def _set_status(self) -> None: diff --git a/blitz/ui/pages/admin/__init__.py b/blitz/ui/pages/admin/__init__.py index ff788f5..cbe7186 100644 --- a/blitz/ui/pages/admin/__init__.py +++ b/blitz/ui/pages/admin/__init__.py @@ -1,7 +1,8 @@ from pathlib import Path -from blitz.ui.blitz_ui import BlitzUI, get_blitz_ui + from nicegui import ui +from blitz.ui.blitz_ui import BlitzUI, get_blitz_ui from blitz.ui.components.element.base import IFrame @@ -16,7 +17,7 @@ def resize_iframe(self) -> None: def render_page(self) -> None: self.resize_iframe() self.ng = IFrame( - src=f"{self.blitz_ui.localhost_url}/admin/", + src="/admin/", frameborder=0, classes="w-full rounded-sm bg-white h-screen overflow-hidden", props="onload=resizeIframe()", diff --git a/blitz/ui/pages/swagger/__init__.py b/blitz/ui/pages/swagger/__init__.py index b477a6f..92654bb 100644 --- a/blitz/ui/pages/swagger/__init__.py +++ b/blitz/ui/pages/swagger/__init__.py @@ -1,6 +1,8 @@ +from pathlib import Path + from nicegui import ui + from blitz.ui.components.element.base import IFrame -from pathlib import Path from blitz.ui.pages.base import BasePage @@ -14,7 +16,7 @@ def resize_iframe(self) -> None: def render(self) -> None: self.resize_iframe() self.ng = IFrame( - src=f"{self.blitz_ui.localhost_url}/api/docs", + src=f"{self.blitz_ui.settings.BLITZ_BASE_URL}/api/docs", frameborder=0, classes="w-full rounded-sm bg-white h-screen overflow-hidden", props="onload=resizeIframe()",