Files
orion/main.py

70 lines
2.0 KiB
Python

from fastapi import FastAPI, Depends, HTTPException
from sqlalchemy.orm import Session
from sqlalchemy import text
from app.core.config import settings
from app.core.lifespan import lifespan
from app.core.database import get_db
from datetime import datetime
from app.api.main import api_router
from fastapi.middleware.cors import CORSMiddleware
import logging
logger = logging.getLogger(__name__)
# FastAPI app with lifespan
app = FastAPI(
title=settings.PROJECT_NAME,
description=settings.DESCRIPTION,
version=settings.VERSION,
lifespan=lifespan
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=settings.ALLOWED_HOSTS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API router
app.include_router(api_router, prefix="/api/v1")
# Public Routes (no authentication required)
# Core application endpoints (Public Routes, no authentication required)
@app.get("/")
def root():
return {
"message": f"{settings.PROJECT_NAME} v{settings.VERSION}",
"status": "operational",
"docs": "/docs",
"features": [
"JWT Authentication",
"Marketplace-aware product import",
"Multi-shop product management",
"Stock management with location tracking"
],
"supported_marketplaces": ["Letzshop", "Amazon", "eBay", "Etsy", "Shopify", "Other"],
"auth_required": "Most endpoints require Bearer token authentication"
}
@app.get("/health")
def health_check(db: Session = Depends(get_db)):
"""Health check endpoint"""
try:
# Test database connection
db.execute(text("SELECT 1"))
return {"status": "healthy", "timestamp": datetime.utcnow()}
except Exception as e:
logger.error(f"Health check failed: {e}")
raise HTTPException(status_code=503, detail="Service unhealthy")
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)