From 94fdf73997efc3cf76734d8a22c1cd2df3210919 Mon Sep 17 00:00:00 2001 From: Maxime de Pachtere Date: Sat, 9 Mar 2024 15:00:12 +0100 Subject: [PATCH] replace localhost with 0.0.0.0 --- blitz/api/blitz_admin.py | 7 ++++--- blitz/api/blitz_api.py | 31 +++++++++++++++---------------- blitz/ui/blitz_ui.py | 2 +- docs/cli/create.md | 6 +++--- docs/cli/start.md | 8 ++++---- tests/e2e/test_cli/test_start.py | 6 +++--- tests/fixtures/blitz.py | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/blitz/api/blitz_admin.py b/blitz/api/blitz_admin.py index 06ed78f..1c641a2 100644 --- a/blitz/api/blitz_admin.py +++ b/blitz/api/blitz_admin.py @@ -1,9 +1,10 @@ +from typing import TYPE_CHECKING + from fastapi import FastAPI -from blitz.db.db import get_sqlite_engine from starlette_admin.contrib.sqla import Admin, ModelView -from typing import TYPE_CHECKING from starlette_admin.views import Link +from blitz.db.db import get_sqlite_engine from blitz.settings import Settings, get_settings if TYPE_CHECKING: @@ -26,7 +27,7 @@ def __init__(self, blitz_app: "BlitzApp", settings: Settings = get_settings()) - Link( label="Go Back to Dashboard", icon="fa fa-link", - url=f"http://localhost:{settings.BLITZ_PORT}/dashboard/projects/{self.blitz_app.name}", + url=f"http://0.0.0.0:{settings.BLITZ_PORT}/dashboard/projects/{self.blitz_app.name}", ) ) diff --git a/blitz/api/blitz_api.py b/blitz/api/blitz_api.py index 9d38a95..a263a23 100644 --- a/blitz/api/blitz_api.py +++ b/blitz/api/blitz_api.py @@ -1,27 +1,26 @@ -from functools import partial import os -from typing import Any - import warnings +from functools import partial +from typing import Any +from fastapi import APIRouter, FastAPI from fastapi.responses import RedirectResponse +from fastapi_crudrouter import SQLAlchemyCRUDRouter # type: ignore +from fastapi_crudrouter.core import CRUDGenerator # type: ignore +from rich import print +from semver import Version +from sqlalchemy.exc import SAWarning + from blitz.api.blitz_admin import BlitzAdmin +from blitz.api.logs import configure as configure_logs +from blitz.app import BlitzApp from blitz.core import BlitzCore from blitz.db.db import get_db from blitz.db.errors import NoChangesDetectedError -from blitz.app import BlitzApp -from fastapi import FastAPI, APIRouter -from fastapi_crudrouter.core import CRUDGenerator # type: ignore -from fastapi_crudrouter import SQLAlchemyCRUDRouter # type: ignore -from semver import Version +from blitz.db.migrations import generate_migration, run_migrations from blitz.models.blitz.resource import BlitzResource from blitz.patch import patch_fastapi_crudrouter from blitz.settings import DBTypes, get_settings -from blitz.db.migrations import generate_migration, run_migrations -from blitz.api.logs import configure as configure_logs -from rich import print - -from sqlalchemy.exc import SAWarning # Patch the crudrouter to work with pydantic v2 patch_fastapi_crudrouter() @@ -192,9 +191,9 @@ def create_blitz_api( "\n".join( ( "\n[bold medium_purple1]Blitz app deployed.", - f" - Blitz UI : http://localhost:{get_settings().BLITZ_PORT}", - f" - Blitz admin : http://localhost:{get_settings().BLITZ_PORT}/admin", - f" - Swagger UI : http://localhost:{get_settings().BLITZ_PORT}/api/docs[/bold medium_purple1]\n", + f" - Blitz UI : http://0.0.0.0:{get_settings().BLITZ_PORT}", + f" - Blitz admin : http://0.0.0.0:{get_settings().BLITZ_PORT}/admin", + f" - Swagger UI : http://0.0.0.0:{get_settings().BLITZ_PORT}/api/docs[/bold medium_purple1]\n", ) ) ) diff --git a/blitz/ui/blitz_ui.py b/blitz/ui/blitz_ui.py index 00532b0..19dbd4d 100644 --- a/blitz/ui/blitz_ui.py +++ b/blitz/ui/blitz_ui.py @@ -19,7 +19,7 @@ def __init__(self, settings: Settings = get_settings()) -> None: self.preprompt = self._get_preprompt() self.settings = settings - self.localhost_url = f"http://localhost:{settings.BLITZ_PORT}" + 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/docs/cli/create.md b/docs/cli/create.md index e0c3a73..913ae25 100644 --- a/docs/cli/create.md +++ b/docs/cli/create.md @@ -39,9 +39,9 @@ $ blitz start demo-blitz-app Please report any issues on https://github.com/Paperz-org/blitz Blitz app deployed. - - Blitz UI : http://localhost:8100 - - Blitz admin : http://localhost:8100/admin - - Swagger UI : http://localhost:8100/api/docs + - Blitz UI : http://0.0.0.0:8100 + - Blitz admin : http://0.0.0.0:8100/admin + - Swagger UI : http://0.0.0.0:8100/api/docs INFO demo-blitz-app Started server process [21292026] INFO demo-blitz-app Waiting for application startup. diff --git a/docs/cli/start.md b/docs/cli/start.md index f11355f..0a86915 100644 --- a/docs/cli/start.md +++ b/docs/cli/start.md @@ -11,9 +11,9 @@ $ blitz start your-blitz-app Please report any issues on https://github.com/Paperz-org/blitz Blitz app deployed. - - Blitz UI : http://localhost:8100 - - Blitz admin : http://localhost:8100/admin - - Swagger UI : http://localhost:8100/api/docs + - Blitz UI : http://0.0.0.0:8100 + - Blitz admin : http://0.0.0.0:8100/admin + - Swagger UI : http://0.0.0.0:8100/api/docs INFO random-blitz-app Started server process [21292026] INFO random-blitz-app Waiting for application startup. @@ -23,4 +23,4 @@ $ blitz start your-blitz-app !!! note - Use `blitz create --help` to see all available options. +Use `blitz create --help` to see all available options. diff --git a/tests/e2e/test_cli/test_start.py b/tests/e2e/test_cli/test_start.py index 13d6099..d71e2a3 100644 --- a/tests/e2e/test_cli/test_start.py +++ b/tests/e2e/test_cli/test_start.py @@ -7,15 +7,15 @@ @pytest.mark.asyncio async def test_blitz_app_urls(blitz_app: None) -> None: async with httpx.AsyncClient(follow_redirects=True) as client: - response = await client.get("http://localhost:8100/admin") + response = await client.get("http://0.0.0.0:8100/admin") assert response.status_code == 200 - response = await client.get("http://localhost:8100/api/docs") + response = await client.get("http://0.0.0.0:8100/api/docs") assert response.status_code == 200 @pytest.mark.asyncio async def test_blitz_app_redirect(blitz_app_path: Path, blitz_app: None) -> None: async with httpx.AsyncClient(follow_redirects=True) as client: - response = await client.get("http://localhost:8100") + response = await client.get("http://0.0.0.0:8100") assert response.status_code == 200 assert response.url.path == f"/dashboard/projects/{blitz_app_path.name}/" diff --git a/tests/fixtures/blitz.py b/tests/fixtures/blitz.py index d1a1625..f1e882a 100644 --- a/tests/fixtures/blitz.py +++ b/tests/fixtures/blitz.py @@ -29,7 +29,7 @@ def blitz_app(cli: Cli, blitz_app_path: Path) -> Iterator[None]: while maximum_try < 20: maximum_try += 1 try: - response = client.get("http://localhost:8100/api/docs") + response = client.get("http://0.0.0.0:8100/api/docs") response.raise_for_status() except Exception: time.sleep(0.2)