Skip to content
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

CORS handling #314

Merged
merged 1 commit into from
Oct 12, 2024
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down
13 changes: 13 additions & 0 deletions llama_deploy/apiserver/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ omit = [

[tool.poetry]
name = "llama-deploy"
version = "0.2.1"
version = "0.2.2"
description = ""
authors = ["Logan Markewich <[email protected]>", "Andrei Fajardo <[email protected]>"]
maintainers = [
Expand Down
Loading