Skip to content

Commit 3f0ccb2

Browse files
committed
Revert "Added middleware"
This reverts commit bac2fde.
1 parent 0bd34d8 commit 3f0ccb2

6 files changed

Lines changed: 24 additions & 520 deletions

File tree

backend/app/api/routes/utils.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,3 @@ def test_email(email_to: EmailStr) -> Message:
2929
@router.get("/health-check/")
3030
async def health_check() -> bool:
3131
return True
32-
33-
34-
@router.get("/cors-debug", tags=["utils"], response_model=dict)
35-
def cors_debug() -> dict:
36-
"""
37-
Endpoint for debugging CORS settings
38-
"""
39-
from app.core.config import settings
40-
41-
return {
42-
"cors_origins": settings.BACKEND_CORS_ORIGINS,
43-
"all_cors_origins": settings.all_cors_origins,
44-
"frontend_host": settings.FRONTEND_HOST,
45-
"environment": settings.ENVIRONMENT,
46-
}

backend/app/core/middleware.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

backend/app/main.py

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,33 @@
1-
import logging
2-
from contextlib import asynccontextmanager
3-
1+
import sentry_sdk
42
from fastapi import FastAPI
5-
from fastapi.staticfiles import StaticFiles
3+
from fastapi.routing import APIRoute
4+
from starlette.middleware.cors import CORSMiddleware
65

76
from app.api.main import api_router
87
from app.core.config import settings
9-
from app.core.middleware import setup_cors
10-
11-
logging.basicConfig(
12-
level=logging.INFO,
13-
format="%(asctime)s %(levelname)s: %(message)s",
14-
datefmt="%Y-%m-%d %H:%M:%S",
15-
)
16-
logger = logging.getLogger(__name__)
178

189

19-
@asynccontextmanager
20-
async def lifespan(app: FastAPI):
21-
"""
22-
Function that runs before the application starts,
23-
and again when the application is shutting down.
10+
def custom_generate_unique_id(route: APIRoute) -> str:
11+
return f"{route.tags[0]}-{route.name}"
2412

25-
For now, just a placeholder, but we can use this to setup
26-
database connections, etc.
27-
"""
28-
yield
2913

14+
if settings.SENTRY_DSN and settings.ENVIRONMENT != "local":
15+
sentry_sdk.init(dsn=str(settings.SENTRY_DSN), enable_tracing=True)
3016

3117
app = FastAPI(
32-
title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json", lifespan=lifespan
18+
title=settings.PROJECT_NAME,
19+
openapi_url=f"{settings.API_V1_STR}/openapi.json",
20+
generate_unique_id_function=custom_generate_unique_id,
3321
)
3422

35-
# Use our custom CORS middleware instead of the default FastAPI one
36-
setup_cors(app)
23+
# Set all CORS enabled origins
24+
if settings.all_cors_origins:
25+
app.add_middleware(
26+
CORSMiddleware,
27+
allow_origins=settings.all_cors_origins,
28+
allow_credentials=True,
29+
allow_methods=["*"],
30+
allow_headers=["*"],
31+
)
3732

3833
app.include_router(api_router, prefix=settings.API_V1_STR)
39-
40-
# Mount the static files directory to serve static files
41-
# app.mount("/static", StaticFiles(directory="static"), name="static")
42-
43-
44-
@app.get("/")
45-
def root():
46-
"""
47-
Root endpoint for health checks
48-
"""
49-
return {"message": "Hello! This is the API root. Go to /docs for API documentation."}
50-
51-
52-
@app.get("/health")
53-
def health_check():
54-
"""
55-
Health check endpoint
56-
"""
57-
return {"status": "ok"}

backend/app/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class User(UserBase, table=True):
4747
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
4848
hashed_password: str
4949
items: list["Item"] = Relationship(back_populates="owner", cascade_delete=True)
50-
tickets: list["Ticket"] = Relationship(back_populates="user", sa_relationship_kwargs={"cascade": "all, delete-orphan"})
5150

5251

5352
# Properties to return via API, id is always required
@@ -209,3 +208,8 @@ class TicketsPublic(SQLModel):
209208
data: list[TicketPublic]
210209
count: int
211210
page: int
211+
212+
213+
# Update User model to include tickets relationship
214+
User.model_rebuild()
215+
setattr(User, "tickets", Relationship(back_populates="user", sa_relationship_kwargs={"cascade": "all, delete-orphan"}))

0 commit comments

Comments
 (0)