52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.responses import RedirectResponse
|
|
from .database import engine, Base
|
|
from .routes import auth_router, courses_router, stats_router, favorites_router, progress_router, course_builder_router, admin_router, learn_router
|
|
from .middleware.cors import setup_cors
|
|
import logging
|
|
|
|
# Configure logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Create FastAPI app
|
|
app = FastAPI(
|
|
title="Auth Learning API",
|
|
description="API for authentication and course management system",
|
|
version="1.0.0",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc"
|
|
)
|
|
|
|
# Setup CORS
|
|
setup_cors(app)
|
|
|
|
# Serve static files (uploads)
|
|
from fastapi.staticfiles import StaticFiles
|
|
app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads")
|
|
|
|
# Create database tables
|
|
@app.on_event("startup")
|
|
async def startup():
|
|
logger.info("Creating database tables...")
|
|
Base.metadata.create_all(bind=engine)
|
|
logger.info("Database tables created")
|
|
|
|
# Include routers
|
|
app.include_router(auth_router, prefix="/api")
|
|
app.include_router(courses_router, prefix="/api")
|
|
app.include_router(stats_router, prefix="/api")
|
|
app.include_router(favorites_router, prefix="/api")
|
|
app.include_router(progress_router, prefix="/api")
|
|
app.include_router(course_builder_router, prefix="/api")
|
|
app.include_router(admin_router, prefix="/api")
|
|
app.include_router(learn_router, prefix="/api")
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return RedirectResponse(url="/docs")
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "healthy", "service": "auth-learning-api"}
|