main.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """
  2. FastAPI application entry point.
  3. Provides RESTful API for the annotation platform.
  4. """
  5. from fastapi import FastAPI
  6. from fastapi.middleware.cors import CORSMiddleware
  7. from contextlib import asynccontextmanager
  8. from database import init_database
  9. from routers import project
  10. @asynccontextmanager
  11. async def lifespan(app: FastAPI):
  12. """
  13. Application lifespan manager.
  14. Initializes database on startup.
  15. """
  16. # Startup: Initialize database
  17. init_database()
  18. yield
  19. # Shutdown: cleanup if needed
  20. # Create FastAPI application instance
  21. app = FastAPI(
  22. title="Annotation Platform API",
  23. description="RESTful API for data annotation management",
  24. version="1.0.0",
  25. lifespan=lifespan
  26. )
  27. # Configure CORS middleware
  28. app.add_middleware(
  29. CORSMiddleware,
  30. allow_origins=[
  31. "http://localhost:4200", # Frontend dev server
  32. "http://localhost:3000", # Alternative frontend port
  33. ],
  34. allow_credentials=True,
  35. allow_methods=["*"],
  36. allow_headers=["*"],
  37. )
  38. # Include routers
  39. app.include_router(project.router)
  40. @app.get("/")
  41. async def root():
  42. """Root endpoint - health check"""
  43. return {
  44. "message": "Annotation Platform API",
  45. "status": "running",
  46. "version": "1.0.0"
  47. }
  48. @app.get("/health")
  49. async def health_check():
  50. """Health check endpoint"""
  51. return {"status": "healthy"}
  52. if __name__ == "__main__":
  53. import uvicorn
  54. uvicorn.run(app, host="0.0.0.0", port=8000)