Skip to content

Commit c58d727

Browse files
committed
fix prod serving not adding cookies on join
1 parent d600251 commit c58d727

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

src/backend/main.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ async def serve_index_html(request: Request = None, response: Response = None, p
8181
Helper function to serve the index.html file or proxy to dev server based on PAD_DEV_MODE.
8282
Optionally sets a pending_pad_id cookie if pad_id is provided.
8383
"""
84-
# Set cookie if pad_id is provided
85-
if pad_id is not None and response is not None:
86-
response.set_cookie(
87-
key="pending_pad_id",
88-
value=str(pad_id),
89-
httponly=True,
90-
secure=True,
91-
samesite="lax"
92-
)
9384

9485
if PAD_DEV_MODE:
9586
try:
@@ -101,18 +92,43 @@ async def serve_index_html(request: Request = None, response: Response = None, p
10192

10293
async with httpx.AsyncClient() as client:
10394
proxy_response = await client.get(url)
104-
response.body = proxy_response.content
105-
response.status_code = proxy_response.status_code
106-
response.media_type = proxy_response.headers.get("content-type")
107-
return response
95+
# Create a new response with the proxied content
96+
final_response = Response(
97+
content=proxy_response.content,
98+
status_code=proxy_response.status_code,
99+
media_type=proxy_response.headers.get("content-type")
100+
)
101+
102+
# Set cookie if pad_id is provided
103+
if pad_id is not None:
104+
final_response.set_cookie(
105+
key="pending_pad_id",
106+
value=str(pad_id),
107+
httponly=True,
108+
secure=True,
109+
samesite="lax"
110+
)
111+
112+
return final_response
108113
except Exception as e:
109114
error_message = f"Error proxying to dev server: {e}"
110115
print(error_message)
111-
response.status_code = 500
112-
return response
116+
return Response(content=error_message, status_code=500)
113117
else:
114118
# For production, serve the static build
115-
return FileResponse(os.path.join(STATIC_DIR, "index.html"), background=response)
119+
file_response = FileResponse(os.path.join(STATIC_DIR, "index.html"))
120+
121+
# Set cookie if pad_id is provided
122+
if pad_id is not None:
123+
file_response.set_cookie(
124+
key="pending_pad_id",
125+
value=str(pad_id),
126+
httponly=True,
127+
secure=True,
128+
samesite="lax"
129+
)
130+
131+
return file_response
116132

117133
@app.get("/pad/{pad_id}")
118134
async def read_pad(

0 commit comments

Comments
 (0)