Add CORS middleware

This commit is contained in:
2026-06-12 13:52:44 +02:00
parent 5e8c826714
commit 336c6aa34e
2 changed files with 15 additions and 3 deletions

View File

@@ -18,12 +18,11 @@ Issues:
- hardcoded secret key in auth.py -> centralise env var loading
- i don't like the error handling in the scanner - doesn't pass errors correctly
- cors for frontend: https://fastapi.tiangolo.com/tutorial/cors
- disableCards var isn't doing anything
- Load cors from env var or something
- BackgroundScanner shouldn't get a single session for the whole lifecycle
- input validation maybe
- too many imports
- inconsistent logging (request logging?)
- rate limiting maybe
- pretty sure the controllers are doing too much stuff
- hardware call tests or sth
- .env.example
- hardware call tests or sth

View File

@@ -2,6 +2,7 @@ import logging
logger = logging.getLogger(__name__)
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.security import OAuth2PasswordBearer
from contextlib import asynccontextmanager
from dotenv import load_dotenv
@@ -37,7 +38,19 @@ async def lifespan(app: FastAPI):
app = FastAPI(lifespan=lifespan)
origins = [
"http://127.0.0.1",
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["GET" "PUT" "POST" "DELETE" "PATCH"],
allow_headers=["*"],
)
app.include_router(token_router)
app.include_router(userManager.user_router)