diff --git a/README.md b/README.md index 3f108a96..05365558 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,12 @@ INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:4501 (Press CTRL+C to quit) ``` +> [!TIP] +> By default, CORS is enabled. If you want to disable it, you can set the `DISABLE_CORS` environment variable: +> ``` +> $ DISABLE_CORS=true python -m llama_deploy.apiserver +> ``` + From another shell, use `llamactl` to create the deployment: ``` diff --git a/llama_deploy/apiserver/app.py b/llama_deploy/apiserver/app.py index 4f0d5a46..f28b2128 100644 --- a/llama_deploy/apiserver/app.py +++ b/llama_deploy/apiserver/app.py @@ -1,7 +1,9 @@ import logging +import os from fastapi import FastAPI from fastapi.responses import JSONResponse +from fastapi.middleware.cors import CORSMiddleware from .routers import status_router, deployments_router from .server import lifespan @@ -10,6 +12,17 @@ app = FastAPI(root_path="/", lifespan=lifespan) + +# Configure CORS middleware if the environment variable is set +if not os.environ.get("DISABLE_CORS", False): + app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # Allows all origins + allow_credentials=True, + allow_methods=["GET", "POST"], + allow_headers=["Content-Type", "Authorization"], + ) + app.include_router(deployments_router) app.include_router(status_router) diff --git a/pyproject.toml b/pyproject.toml index 0089b993..3ffff368 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ omit = [ [tool.poetry] name = "llama-deploy" -version = "0.2.1" +version = "0.2.2" description = "" authors = ["Logan Markewich ", "Andrei Fajardo "] maintainers = [