Fix type errors
This commit is contained in:
@ -189,7 +189,9 @@ def create_router(dependencies: AdminDependencies) -> APIRouter:
|
||||
)
|
||||
|
||||
path = f"/auth_cb#access_token={access_token}&refresh_token={refresh_token}"
|
||||
callback_url = os.path.join(dependencies.settings.frontend_url, path)
|
||||
callback_url = os.path.join("admin", path)
|
||||
if dependencies.settings.frontend_test_url:
|
||||
callback_url = os.path.join(dependencies.settings.frontend_test_url, path)
|
||||
origin = "UNKNOWN"
|
||||
if request.client:
|
||||
origin = request.client.host
|
||||
|
||||
@ -4,12 +4,14 @@
|
||||
#
|
||||
from collections.abc import AsyncGenerator
|
||||
import logging
|
||||
import pathlib
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI, Request, status
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@ -29,6 +31,28 @@ from .settings import AdminServerSettings
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def valid_frontend_directory(frontend_dir: pathlib.Path) -> bool:
|
||||
"""Validate frontend dir."""
|
||||
if not frontend_dir.exists():
|
||||
return False
|
||||
if not frontend_dir.is_dir():
|
||||
return False
|
||||
if (frontend_dir / "index.html").exists():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def setup_frontend(app: FastAPI, settings: AdminServerSettings) -> None:
|
||||
"""Setup frontend."""
|
||||
if not settings.frontend_dir:
|
||||
return
|
||||
if not valid_frontend_directory(settings.frontend_dir):
|
||||
LOG.error("Error: Not a valid frontend directory: %s", settings.frontend_dir)
|
||||
return
|
||||
frontend = StaticFiles(directory=settings.frontend_dir)
|
||||
app.mount("/admin", frontend, name="frontend")
|
||||
|
||||
|
||||
def create_admin_app(
|
||||
settings: AdminServerSettings,
|
||||
create_db: bool = False,
|
||||
@ -104,5 +128,6 @@ def create_admin_app(
|
||||
dependencies = BaseDependencies(settings, get_db_session, get_async_session)
|
||||
|
||||
app.include_router(api.create_api_router(dependencies))
|
||||
setup_frontend(app, settings)
|
||||
|
||||
return app
|
||||
|
||||
@ -40,7 +40,8 @@ class AdminServerSettings(BaseSettings):
|
||||
password_manager_directory: Path | None = None
|
||||
oidc: OidcSettings | None = None
|
||||
frontend_origin: str = Field(default="*")
|
||||
frontend_url: str
|
||||
frontend_test_url: str | None = Field(default=None)
|
||||
frontend_dir: Path | None = None
|
||||
|
||||
@property
|
||||
def admin_db(self) -> URL:
|
||||
|
||||
Reference in New Issue
Block a user