72 lines
2.0 KiB
Python
72 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")
|
|
|
|
# Add this temporary endpoint to your router:
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|