Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from app.core.config import settings | |
| from app.db.base import Base, engine | |
| from app.api.auth import router as auth_router | |
| from app.api.products import router as products_router | |
| from app.api.categories import router as categories_router | |
| from app.api.cart import router as cart_router | |
| from app.api.orders import router as orders_router | |
| from app.api.seed import router as seed_router | |
| from app.api.ai_search import router as ai_search_router | |
| from app.api.home import router as home_router | |
| from app.api.admin import router as admin_router | |
| from app.api.notifications import router as notifications_router | |
| from app.api.external import router as external_router | |
| from app.api.settings import router as settings_router | |
| from app.api.analytics import router as analytics_router | |
| # Import models to register them with Base | |
| import app.models.user # noqa: F401 | |
| import app.models.product # noqa: F401 | |
| import app.models.cart # noqa: F401 | |
| import app.models.order # noqa: F401 | |
| import app.models.notification # noqa: F401 | |
| import app.models.settings # noqa: F401 | |
| import app.models.home # noqa: F401 | |
| import app.models.analytics # noqa: F401 | |
| from fastapi.middleware.gzip import GZipMiddleware | |
| from contextlib import asynccontextmanager | |
| async def lifespan(app: FastAPI): | |
| # Startup logic - Minimal and fast | |
| print(">>> [MAIN] Application starting (DB maintenance disabled).") | |
| yield | |
| # Shutdown logic (optional) | |
| # Shutdown logic (optional) | |
| def create_app() -> FastAPI: | |
| app = FastAPI( | |
| title="VortexCommerce API", | |
| description="AI-Powered Bilingual E-Commerce Platform", | |
| version="1.0.0", | |
| docs_url="/docs", | |
| redoc_url="/redoc", | |
| lifespan=lifespan | |
| ) | |
| # CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.cors_origins_list, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Response Compression | |
| app.add_middleware(GZipMiddleware, minimum_size=1000) | |
| # Routers | |
| app.include_router(auth_router, prefix="/api") | |
| app.include_router(products_router, prefix="/api") | |
| app.include_router(categories_router, prefix="/api") | |
| app.include_router(cart_router, prefix="/api") | |
| app.include_router(orders_router, prefix="/api") | |
| app.include_router(seed_router, prefix="/api") | |
| app.include_router(external_router, prefix="/api") | |
| app.include_router(ai_search_router, prefix="/api") | |
| app.include_router(admin_router, prefix="/api") | |
| app.include_router(notifications_router, prefix="/api") | |
| print(">>> [MAIN] Registering analytics router at /api/analytics") | |
| app.include_router(analytics_router, prefix="/api") | |
| app.include_router(settings_router, prefix="/api") | |
| app.include_router(home_router, prefix="/api") | |
| VERSION = "2.0.0-FINAL-CATALOG" | |
| async def root(): | |
| """FORCE RELOAD Health Check""" | |
| return { | |
| "status": "online", | |
| "service": "VortexCommerce-CORE-API", | |
| "version": VERSION, | |
| "ts": "2026-03-16-T-13-45", | |
| "msg": "New container is active" | |
| } | |
| async def health_check(): | |
| return { | |
| "isSuccess": True, | |
| "value": { | |
| "status": "healthy", | |
| "service": "VortexCommerce API", | |
| "version": VERSION | |
| }, | |
| "statusCode": 200, | |
| } | |
| print(f">>> [MAIN] Application initialized. Version: {VERSION}") | |
| return app | |
| app = create_app() | |