| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- """
- FastAPI application entry point.
- Provides RESTful API for the annotation platform with JWT authentication.
- """
- from fastapi import FastAPI
- from fastapi.middleware.cors import CORSMiddleware
- from contextlib import asynccontextmanager
- from database import init_database
- from routers import project, task, annotation, auth, oauth
- from middleware.auth_middleware import AuthMiddleware
- @asynccontextmanager
- async def lifespan(app: FastAPI):
- """
- Application lifespan manager.
- Initializes database on startup.
- """
- # Startup: Initialize database
- init_database()
- yield
- # Shutdown: cleanup if needed
- # Create FastAPI application instance
- app = FastAPI(
- title="Annotation Platform API",
- description="RESTful API for data annotation management with JWT authentication",
- version="1.0.0",
- lifespan=lifespan
- )
- # Configure CORS middleware (must be added first)
- app.add_middleware(
- CORSMiddleware,
- allow_origins=[
- "http://localhost:4200", # Frontend dev server
- "http://localhost:3000", # Alternative frontend port
- ],
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- # Add authentication middleware (after CORS)
- app.add_middleware(AuthMiddleware)
- # Include routers
- app.include_router(auth.router)
- app.include_router(oauth.router)
- app.include_router(project.router)
- app.include_router(task.router)
- app.include_router(annotation.router)
- @app.get("/")
- async def root():
- """Root endpoint - health check"""
- return {
- "message": "Annotation Platform API",
- "status": "running",
- "version": "1.0.0"
- }
- @app.get("/health")
- async def health_check():
- """Health check endpoint"""
- return {"status": "healthy"}
- if __name__ == "__main__":
- import uvicorn
- uvicorn.run(app, host="0.0.0.0", port=8000)
|