Skip to content

feat: add cors support #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
LOG_LEVEL=INFO
API_HOST=127.0.0.1
API_PORT=8000
CORS_ALLOWED_ORIGINS="*" # comma-separated list of allowed origins
AGENTS_REF='{"agent_uuid": "agent_module_name:agent_var"}'
AGENT_MANIFEST_PATH=manifest.json
AGWS_STORAGE_PERSIST=True
Expand Down
2 changes: 1 addition & 1 deletion src/agent_workflow_server/agents/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _resolve_agent(name: str, path: str) -> AgentInfo:
# Load manifest. Check in paths below (in order)
manifest_paths = [
os.path.join(os.path.dirname(module.__file__), "manifest.json"),
os.environ.get("AGENT_MANIFEST_PATH", "manifest.json") or "manifest.json",
os.getenv("AGENT_MANIFEST_PATH", "manifest.json") or "manifest.json",
]

for manifest_path in manifest_paths:
Expand Down
2 changes: 1 addition & 1 deletion src/agent_workflow_server/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

CustomLoggerHandler = handler

LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper()
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
logging.basicConfig(level=LOG_LEVEL, handlers=[CustomLoggerHandler], force=True)
11 changes: 10 additions & 1 deletion src/agent_workflow_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import uvicorn.logging
from dotenv import load_dotenv
from fastapi import Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware

import agent_workflow_server.logging.logger # noqa: F401
from agent_workflow_server.agents.load import load_agents
Expand Down Expand Up @@ -49,6 +50,14 @@
dependencies=[Depends(authentication_with_api_key)],
)

app.add_middleware(
CORSMiddleware,
allow_origins=os.getenv("CORS_ALLOWED_ORIGINS", "*").split(","),
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


def signal_handler(sig, frame):
logger.warning(f"Received {signal.Signals(sig).name}. Exiting...")
Expand All @@ -60,7 +69,7 @@ def start():
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
load_agents()
n_workers = int(os.environ.get("NUM_WORKERS", 5))
n_workers = int(os.getenv("NUM_WORKERS", 5))

loop = asyncio.get_event_loop()
loop.create_task(start_workers(n_workers))
Expand Down