from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from crowdtls.apis.v1 import app as api_v1 from crowdtls.db import create_db_and_tables from crowdtls.logs import logger app = FastAPI() app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["POST"], allow_headers=["*"]) app.include_router(api_v1, prefix="/api/v1") @app.on_event("startup") async def startup_event(): logger.info("Creating database and tables") try: await create_db_and_tables() except Exception: logger.error("Failed to create database and tables") raise if __name__ == "__main__": app.run()