acupedia-api/app/main.py

94 lines
3.0 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
import os
from dotenv import load_dotenv
from app.features.auth import router as auth_router
from app.features.access import router as access_router
from app.features.content.api import router as contents_router
from app.features.search.api import router as search_router
from app.features.cart import router as cart_router
from app.features.checkout import router as checkout_router
from app.features.admin import router as admin_router
from app.features.webhooks import router as webhooks_router
from app.cache.health import router as cache_health_router
from app.core.settings import settings
from app.db.session import get_db_session
from app.lifespan import lifespan
_backend_env = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env")
load_dotenv(dotenv_path=_backend_env, override=True)
app = FastAPI(
title="Acupedia Platform API",
description="API for managing content, auth, subscriptions, and payments.",
version="1.0.0",
lifespan=lifespan
)
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:8081",
"http://127.0.0.1:8081",
"http://localhost:3000",
"http://127.0.0.1:3000"
],
allow_origin_regex=r"https?://.*",
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Register API routers
app.include_router(auth_router, prefix="/api")
app.include_router(access_router, prefix="/api")
app.include_router(contents_router,prefix="/api")
app.include_router(cart_router, prefix="/api")
app.include_router(checkout_router, prefix="/api")
app.include_router(admin_router, prefix="/api")
app.include_router(webhooks_router, prefix="/api")
app.include_router(cache_health_router, prefix="/api")
app.include_router(search_router, prefix="/api")
# @app.get("/")
# async def root() -> dict[str,Any]:
# connection = await get_db_session()
# try:
# with connection.cursor() as cursor:
# cursor.execute("SELECT current_database();")
# database_name = cursor.fetchone()[0]
# finally:
# connection.close()
# minio_status = "active"
# bucket_count = 0
# try:
# minio_client = get_minio_client()
# buckets = minio_client.list_buckets()
# bucket_count = len(buckets)
# except Exception:
# minio_status = "MinIO not activated (bypassed)"
# return {
# "status": "Acupedia Backend is Running",
# "version": "1.0.0",
# "docs_url": "/docs",
# "environment": os.getenv("ENVIRONMENT", "development"),
# "database_name": database_name,
# "database_schema": settings.database_schema,
# "minio_endpoint": settings.minio_endpoint,
# "minio_status": minio_status,
# "bucket_count": bucket_count if minio_status == "active" else "MinIO not activated, bypassing",
# }
if __name__ == "__main__":
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)