from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from .routers import users, token, mail, events from .dependencies import user_add import os app = FastAPI() origins = [ "http://localhost:8084", "https://backend.valczeryba.ovh" ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(users.router) app.include_router(token.router) app.include_router(mail.router) app.include_router(events.router) @app.on_event("startup") async def startup_event(): if os.environ.get("USERNAME_ADMIN") is not None and os.environ.get("PASSWORD_ADMIN") is not None: user_add.add(username=os.environ["USERNAME_ADMIN"], password=os.environ["PASSWORD_ADMIN"], roles="Admin") else: print("User admin not added") if os.environ.get("USERNAME_TEST") is not None and os.environ.get("PASSWORD_TEST") is not None: user_add.add(username=os.environ["USERNAME_TEST"], password=os.environ["PASSWORD_TEST"], roles="User") else: print("User test not added") @app.get("/") async def root(): return {"message": "Hello World !"}