Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Add CORS Middleware to Resolve XMLHttpRequest Error (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunteraraujo authored Sep 2, 2023
1 parent bc731e0 commit 291f7f2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions autogpt/sdk/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fastapi import APIRouter, FastAPI, UploadFile
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
from hypercorn.asyncio import serve
from hypercorn.config import Config

Expand Down Expand Up @@ -35,6 +36,21 @@ def start(self, port: int = 8000, router: APIRouter = base_router):
version="v0.4",
)

# Add CORS middleware
origins = [
"http://localhost:5000",
"http://127.0.0.1:5000",
# Add any other origins you want to whitelist
]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.include_router(router)
app.add_middleware(AgentMiddleware, agent=self)
config.loglevel = "ERROR"
Expand Down

0 comments on commit 291f7f2

Please sign in to comment.