main.py 1.4 KB

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