48 lines
1.3 KiB
Python
Raw Normal View History

2023-10-10 22:39:23 +02:00
from fastapi import FastAPI
2023-10-18 23:59:18 +02:00
from fastapi.middleware.cors import CORSMiddleware
2023-10-10 22:39:23 +02:00
2023-11-06 23:29:12 +01:00
from .routers import users, token, mail, events
2023-10-13 21:44:30 +02:00
from .dependencies import user_add
2023-10-11 23:45:12 +02:00
2023-10-17 21:44:49 +02:00
import os
2023-10-10 22:39:23 +02:00
app = FastAPI()
2023-10-18 23:59:18 +02:00
origins = [
"http://localhost:8084",
2024-04-29 22:58:36 +02:00
"https://backend.valczeryba.ovh",
2024-05-29 23:36:11 +02:00
"https://facebook.com",
"https://fetlife.com",
"https://backoffice.valczeryba.ovh"
2023-10-18 23:59:18 +02:00
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
2023-10-10 22:39:23 +02:00
app.include_router(users.router)
2023-10-12 00:04:18 +02:00
app.include_router(token.router)
2023-10-15 16:17:37 +02:00
app.include_router(mail.router)
2023-11-06 23:29:12 +01:00
app.include_router(events.router)
2023-10-10 22:39:23 +02:00
2023-10-13 21:44:30 +02:00
@app.on_event("startup")
async def startup_event():
2023-10-17 22:01:59 +02:00
if os.environ.get("USERNAME_ADMIN") is not None and os.environ.get("PASSWORD_ADMIN") is not None:
2023-10-17 21:37:36 +02:00
user_add.add(username=os.environ["USERNAME_ADMIN"], password=os.environ["PASSWORD_ADMIN"], roles="Admin")
2023-10-17 22:01:59 +02:00
else:
print("User admin not added")
if os.environ.get("USERNAME_TEST") is not None and os.environ.get("PASSWORD_TEST") is not None:
2023-10-17 21:37:36 +02:00
user_add.add(username=os.environ["USERNAME_TEST"], password=os.environ["PASSWORD_TEST"], roles="User")
2023-10-17 22:01:59 +02:00
else:
print("User test not added")
2023-10-13 21:44:30 +02:00
2023-10-10 22:39:23 +02:00
@app.get("/")
async def root():
2024-05-29 23:36:11 +02:00
return {"message": "Hello World !"}