mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-02 21:50:16 +00:00
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import os
|
|
import sys
|
|
import pathlib
|
|
|
|
# Add project root to Python path to import shared utils
|
|
_project_root = pathlib.Path(__file__).parent.parent
|
|
if str(_project_root) not in sys.path:
|
|
sys.path.insert(0, str(_project_root))
|
|
|
|
from utils import traceroot_wrapper as traceroot
|
|
from app import api
|
|
from app.component.environment import auto_include_routers, env
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
# Import middleware to register BabelMiddleware
|
|
import app.middleware # noqa: F401
|
|
|
|
# Import exception handlers to register them
|
|
import app.exception.handler # noqa: F401
|
|
|
|
# Only initialize traceroot if enabled
|
|
if traceroot.is_enabled():
|
|
from traceroot.integrations.fastapi import connect_fastapi
|
|
|
|
connect_fastapi(api)
|
|
|
|
logger = traceroot.get_logger("server_main")
|
|
|
|
prefix = env("url_prefix", "")
|
|
auto_include_routers(api, prefix, "app/controller")
|
|
public_dir = os.environ.get("PUBLIC_DIR") or os.path.join(
|
|
os.path.dirname(__file__), "app", "public"
|
|
)
|
|
if not os.path.isdir(public_dir):
|
|
try:
|
|
os.makedirs(public_dir, exist_ok=True)
|
|
logger.warning(f"Public directory did not exist. Created: {public_dir}")
|
|
except Exception as e:
|
|
logger.error(
|
|
f"Public directory missing and could not be created: {public_dir}. Error: {e}"
|
|
)
|
|
public_dir = None
|
|
|
|
if public_dir and os.path.isdir(public_dir):
|
|
api.mount("/public", StaticFiles(directory=public_dir), name="public")
|
|
else:
|
|
logger.warning("Skipping /public mount because public directory is unavailable")
|