2023-06-06 15:51:54 -07:00
|
|
|
from fastapi import FastAPI
|
2023-06-07 14:35:48 -07:00
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
2023-06-06 15:51:54 -07:00
|
|
|
|
2023-06-07 15:41:47 -07:00
|
|
|
from crowdtls.apis.v1 import app as api_v1
|
2023-06-07 14:35:48 -07:00
|
|
|
from crowdtls.db import create_db_and_tables
|
|
|
|
from crowdtls.logs import logger
|
2023-06-06 15:51:54 -07:00
|
|
|
|
|
|
|
app = FastAPI()
|
2023-06-07 14:35:48 -07:00
|
|
|
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["POST"], allow_headers=["*"])
|
2023-06-07 15:41:47 -07:00
|
|
|
app.include_router(api_v1, prefix="/api/v1")
|
2023-06-06 15:51:54 -07:00
|
|
|
|
|
|
|
|
2023-06-07 14:35:48 -07:00
|
|
|
@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
|
2023-06-07 15:40:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run()
|