Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

added CORS middleware

Dillon DuPont0e834c0a6f21
diff --git a/libs/python/computer-server/computer_server/main.py b/libs/python/computer-server/computer_server/main.py
index 4d3dbd52f9..ea3dcc808d 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)
[email protected]("/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)