52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
import os
|
|
import sys
|
|
|
|
# Add backend directory to sys.path to resolve 'app' module
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from app.core.registry import TOOLS_REGISTRY, search_tools
|
|
from app.core.cleanup import start_scheduler, cleanup_all, init_temp_dir
|
|
from app.tools import server_ops, image_ops, video_ops
|
|
import contextlib
|
|
|
|
@contextlib.asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
cleanup_all()
|
|
scheduler = start_scheduler()
|
|
yield
|
|
scheduler.shutdown()
|
|
|
|
app = FastAPI(title="Web Utils 2026", description="Personal Web Utilities Server", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(server_ops.router, prefix="/api/tools", tags=["tools"])
|
|
app.include_router(image_ops.router, prefix="/api/tools", tags=["images"])
|
|
app.include_router(video_ops.router, prefix="/api/tools/video", tags=["video"])
|
|
|
|
@app.get("/api/registry")
|
|
def get_registry(q: str | None = None):
|
|
"""프론트엔드 메뉴 구성을 위한 도구 목록 반환"""
|
|
return search_tools(q or "")
|
|
|
|
# Static Files Serving (Frontend 빌드 결과물 서빙용 - 배포 시 활성화)
|
|
# 개발 중에는 Frontend Dev Server(Vite)를 별도로 띄우는 것이 일반적이지만,
|
|
# 최종 배포 형태를 고려해 코드를 남겨둡니다.
|
|
# frontend_dist = "../frontend/dist"
|
|
# if os.path.exists(frontend_dist):
|
|
# app.mount("/", StaticFiles(directory=frontend_dist, html=True), name="static")
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
# Use 'app.main:app' to ensure reliable reloading from backend root
|
|
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
|