[crawler_platform 삭제]
This commit is contained in:
@@ -44,6 +44,7 @@ from ont_platform.api.deps import ( # noqa: E402
|
||||
get_app_context,
|
||||
initialize_app_context,
|
||||
)
|
||||
from ont_platform.api.product_backend import include_product_backend # noqa: E402
|
||||
|
||||
platform_config = importlib.import_module("ont_platform.config")
|
||||
|
||||
@@ -80,7 +81,7 @@ PLATFORM_VERSION = "0.0.1"
|
||||
def _include_phase_routers(app: FastAPI) -> None:
|
||||
"""Attach routers whose dependencies are enabled for the configured phase."""
|
||||
settings = platform_config.load_settings()
|
||||
enabled_routes: list[str] = []
|
||||
enabled_routes: list[str] = ["product-backend"]
|
||||
|
||||
if settings.phase >= platform_config.Phase.TRAFILATURA:
|
||||
try:
|
||||
@@ -144,6 +145,7 @@ def create_app() -> FastAPI:
|
||||
version=PLATFORM_VERSION,
|
||||
lifespan=lifespan,
|
||||
)
|
||||
include_product_backend(app)
|
||||
|
||||
# ─── /health ──────────────────────────────────────────────────────
|
||||
@app.get("/health", tags=["meta"])
|
||||
|
||||
87
ontology_platform/ont_platform/api/product_backend.py
Normal file
87
ontology_platform/ont_platform/api/product_backend.py
Normal file
@@ -0,0 +1,87 @@
|
||||
"""Product backend bridge for the migrated crawler platform.
|
||||
|
||||
This module mounts the product API that the current frontend already uses:
|
||||
projects, sources, crawl jobs, claims, ontology registry, graph views, and
|
||||
exports. The implementation now lives inside ``ontology_platform`` so the root
|
||||
``crawler_platform`` folder can be retired after verification.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
|
||||
from crawler_platform.app.api.routes import register_routes
|
||||
from crawler_platform.app.core.database.session import init_db
|
||||
|
||||
|
||||
_ONTOLOGY_ROOT = Path(__file__).resolve().parents[2]
|
||||
_DEFAULT_DB_PATH = _ONTOLOGY_ROOT / "data" / "crawler_platform.db"
|
||||
_DEFAULT_STATIC_DIR = _ONTOLOGY_ROOT / "web" / "static"
|
||||
|
||||
|
||||
def product_database_url() -> str:
|
||||
configured = os.getenv("CRAWLER_DATABASE_URL")
|
||||
if configured:
|
||||
return configured
|
||||
_DEFAULT_DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
return f"sqlite:///{_DEFAULT_DB_PATH.as_posix()}"
|
||||
|
||||
|
||||
def product_static_dir() -> Path:
|
||||
configured = os.getenv("ONTOLOGY_PRODUCT_STATIC_DIR")
|
||||
return Path(configured) if configured else _DEFAULT_STATIC_DIR
|
||||
|
||||
|
||||
def include_product_backend(app: FastAPI) -> None:
|
||||
"""Mount the migrated product API and SPA routes on the given app."""
|
||||
|
||||
database_url = product_database_url()
|
||||
init_db(database_url)
|
||||
register_routes(app, database_url)
|
||||
_remove_route(app, "/health", {"GET"})
|
||||
app.state.product_database_url = database_url
|
||||
|
||||
app.add_exception_handler(KeyError, _handle_key_error)
|
||||
|
||||
@app.get("/static/{asset_path:path}", include_in_schema=False)
|
||||
def static_or_spa(asset_path: str):
|
||||
static_root = product_static_dir().resolve()
|
||||
target = (static_root / asset_path).resolve()
|
||||
try:
|
||||
target.relative_to(static_root)
|
||||
except ValueError:
|
||||
return JSONResponse(status_code=404, content={"detail": "not found"})
|
||||
|
||||
if target.is_file():
|
||||
return FileResponse(target)
|
||||
index = static_root / "index.html"
|
||||
if index.is_file():
|
||||
return FileResponse(index)
|
||||
return JSONResponse(status_code=404, content={"detail": "frontend build not found"})
|
||||
|
||||
@app.get("/", include_in_schema=False)
|
||||
def admin_ui():
|
||||
index = product_static_dir() / "index.html"
|
||||
if index.is_file():
|
||||
return FileResponse(index)
|
||||
return JSONResponse(status_code=404, content={"detail": "frontend build not found"})
|
||||
|
||||
|
||||
def _handle_key_error(_request: Request, exc: KeyError) -> JSONResponse:
|
||||
detail = str(exc.args[0]) if exc.args else "not found"
|
||||
return JSONResponse(status_code=404, content={"detail": detail})
|
||||
|
||||
|
||||
def _remove_route(app: FastAPI, path: str, methods: set[str]) -> None:
|
||||
app.router.routes = [
|
||||
route
|
||||
for route in app.router.routes
|
||||
if not (
|
||||
getattr(route, "path", None) == path
|
||||
and set(getattr(route, "methods", set())) == methods
|
||||
)
|
||||
]
|
||||
Reference in New Issue
Block a user