From 0e834c0a6f21db0a282fdd021a3dfeaf72e26f9f Mon Sep 17 00:00:00 2001 From: Dillon DuPont Date: Thu, 28 Aug 2025 12:51:45 -0400 Subject: [PATCH] added CORS middleware --- .../computer-server/computer_server/main.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/libs/python/computer-server/computer_server/main.py b/libs/python/computer-server/computer_server/main.py index 4d3dbd52..ea3dcc80 100644 --- a/libs/python/computer-server/computer_server/main.py +++ b/libs/python/computer-server/computer_server/main.py @@ -15,6 +15,7 @@ import aiohttp import hashlib import time import platform +from fastapi.middleware.cors import CORSMiddleware # Set up logging with more detail logger = logging.getLogger(__name__) @@ -31,6 +32,16 @@ app = FastAPI( websocket_max_size=WEBSOCKET_MAX_SIZE, ) +# CORS configuration +origins = ["*"] +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + protocol_version = 1 try: from importlib.metadata import version @@ -428,9 +439,6 @@ async def cmd_endpoint( headers={ "Cache-Control": "no-cache", "Connection": "keep-alive", - "Access-Control-Allow-Origin": "*", - "Access-Control-Allow-Methods": "POST, OPTIONS", - "Access-Control-Allow-Headers": "Content-Type, X-Container-Name, X-API-Key" } ) @@ -662,27 +670,10 @@ async def agent_response_endpoint( headers = { "Cache-Control": "no-cache", "Connection": "keep-alive", - "Access-Control-Allow-Methods": "POST, OPTIONS", - "Access-Control-Allow-Headers": "Content-Type, X-Container-Name, X-API-Key", - "Access-Control-Allow-Origin": "*", } return JSONResponse(content=payload, headers=headers) -@app.options("/responses") -async def agent_response_options(request: Request): - """CORS preflight for /responses""" - headers = { - "Cache-Control": "no-cache", - "Connection": "keep-alive", - "Access-Control-Allow-Methods": "POST, OPTIONS", - "Access-Control-Allow-Headers": "Content-Type, X-Container-Name, X-API-Key", - "Access-Control-Max-Age": "600", - "Access-Control-Allow-Origin": "*", - } - return JSONResponse(content={}, headers=headers) - - if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)