Skip to content

Commit

Permalink
replace localhost with 0.0.0.0 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
mde-pach authored Mar 9, 2024
1 parent ecb5d6d commit 5cc8832
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion blitz/api/blitz_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://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}",
)
)
self.admin.add_view(Link(label="GitHub", icon="fa-brands fa-github", url="https://github.com/Paperz-org/blitz"))
Expand Down
31 changes: 15 additions & 16 deletions blitz/api/blitz_api.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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",
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion blitz/ui/blitz_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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
Expand Down
6 changes: 3 additions & 3 deletions docs/cli/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ $ blitz start demo-blitz-app
<span style="color: yellow; font-weight: bold;">Please report any issues on https://github.com/Paperz-org/blitz</span>

<span style="color: #af87ff; font-weight: bold;">Blitz app deployed.</span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz UI : <a style="cursor: pointer" href="http://localhost:8100" target="_blank" rel="noopener noreferrer">http://localhost:8100</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz admin : <a style="cursor: pointer" href="http://localhost:8100/admin" target="_blank" rel="noopener noreferrer">http://localhost:8100/admin</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Swagger UI : <a style="cursor: pointer" href="http://localhost:8100/api/docs" target="_blank" rel="noopener noreferrer">http://localhost:8100/api/docs</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz UI : <a style="cursor: pointer" href="http://0.0.0.0:8100" target="_blank" rel="noopener noreferrer">http://0.0.0.0:8100</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz admin : <a style="cursor: pointer" href="http://0.0.0.0:8100/admin" target="_blank" rel="noopener noreferrer">http://0.0.0.0:8100/admin</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Swagger UI : <a style="cursor: pointer" href="http://0.0.0.0:8100/api/docs" target="_blank" rel="noopener noreferrer">http://0.0.0.0:8100/api/docs</a></span>

<span style="color: lightblue; font-weight: bold;">INFO</span> demo-blitz-app Started server process [21292026]
<span style="color: lightblue; font-weight: bold;">INFO</span> demo-blitz-app Waiting for application startup.
Expand Down
6 changes: 3 additions & 3 deletions docs/cli/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ $ blitz start your-blitz-app
<span style="color: yellow; font-weight: bold;">Please report any issues on https://github.com/Paperz-org/blitz</span>

<span style="color: #af87ff; font-weight: bold;">Blitz app deployed.</span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz UI : <a style="cursor: pointer" href="http://localhost:8100" target="_blank" rel="noopener noreferrer">http://localhost:8100</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz admin : <a style="cursor: pointer" href="http://localhost:8100/admin" target="_blank" rel="noopener noreferrer">http://localhost:8100/admin</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Swagger UI : <a style="cursor: pointer" href="http://localhost:8100/api/docs" target="_blank" rel="noopener noreferrer">http://localhost:8100/api/docs</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz UI : <a style="cursor: pointer" href="http://0.0.0.0:8100" target="_blank" rel="noopener noreferrer">http://0.0.0.0:8100</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Blitz admin : <a style="cursor: pointer" href="http://0.0.0.0:8100/admin" target="_blank" rel="noopener noreferrer">http://0.0.0.0:8100/admin</a></span>
<span style="color: #af87ff; font-weight: bold;"> - Swagger UI : <a style="cursor: pointer" href="http://0.0.0.0:8100/api/docs" target="_blank" rel="noopener noreferrer">http://0.0.0.0:8100/api/docs</a></span>

<span style="color: lightblue; font-weight: bold;">INFO</span> random-blitz-app Started server process [21292026]
<span style="color: lightblue; font-weight: bold;">INFO</span> random-blitz-app Waiting for application startup.
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/test_cli/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}/"
2 changes: 1 addition & 1 deletion tests/fixtures/blitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5cc8832

Please sign in to comment.