rebuild(stage-14): deliver migration and recovery tooling
This commit is contained in:
@@ -2,7 +2,8 @@ import asyncio
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from backend.bootstrap.container import build_container
|
||||
from backend.bootstrap.logging import configure_logging
|
||||
@@ -59,4 +60,16 @@ def create_application(settings: Settings | None = None) -> FastAPI:
|
||||
install_request_context(application)
|
||||
install_error_handlers(application)
|
||||
application.include_router(api_router, prefix="/api")
|
||||
if runtime.frontend_dist_directory.joinpath("index.html").is_file():
|
||||
frontend_root = runtime.frontend_dist_directory.resolve()
|
||||
|
||||
@application.get("/{requested_path:path}", include_in_schema=False)
|
||||
def frontend(requested_path: str) -> FileResponse:
|
||||
if requested_path == "api" or requested_path.startswith("api/"):
|
||||
raise HTTPException(status_code=404)
|
||||
candidate = frontend_root.joinpath(requested_path).resolve()
|
||||
if candidate.is_relative_to(frontend_root) and candidate.is_file():
|
||||
return FileResponse(candidate)
|
||||
return FileResponse(frontend_root / "index.html")
|
||||
|
||||
return application
|
||||
|
||||
@@ -41,6 +41,7 @@ class Settings:
|
||||
host: str
|
||||
port: int
|
||||
encryption_key: str | None
|
||||
frontend_dist_directory: Path = PROJECT_ROOT / "frontend" / "dist"
|
||||
timezone: str = "Asia/Shanghai"
|
||||
|
||||
@classmethod
|
||||
@@ -63,6 +64,9 @@ class Settings:
|
||||
os.getenv("APP_PRIVATE_MENTOR_SKILLS_DIR", ""),
|
||||
data_directory / "private-mentor-skills",
|
||||
)
|
||||
frontend_dist_directory = _resolve_path(
|
||||
os.getenv("APP_FRONTEND_DIST", ""), PROJECT_ROOT / "frontend" / "dist"
|
||||
)
|
||||
log_file = _resolve_path(
|
||||
os.getenv("APP_LOG_FILE", ""),
|
||||
data_directory / "logs" / "application.log",
|
||||
@@ -80,6 +84,7 @@ class Settings:
|
||||
database_path=database_path,
|
||||
mentor_skills_directory=mentor_skills_directory,
|
||||
private_mentor_skills_directory=private_mentor_skills_directory,
|
||||
frontend_dist_directory=frontend_dist_directory,
|
||||
log_file=log_file,
|
||||
log_level=log_level,
|
||||
host=os.getenv("APP_HOST", "127.0.0.1").strip() or "127.0.0.1",
|
||||
@@ -98,6 +103,7 @@ class Settings:
|
||||
database_path=root / "xiaobai-test.db",
|
||||
mentor_skills_directory=PROJECT_ROOT / "config" / "mentor-skills",
|
||||
private_mentor_skills_directory=root / "private-mentor-skills",
|
||||
frontend_dist_directory=root / "frontend-dist",
|
||||
log_file=None,
|
||||
log_level="CRITICAL",
|
||||
host="127.0.0.1",
|
||||
|
||||
Reference in New Issue
Block a user