Skip to content

Add opt-in CORS support via PARAKEET_CORS_ORIGINS env var - #1

Open
arvindvenkataramani wants to merge 1 commit into
yashhere:mainfrom
arvindvenkataramani:feat/cors-support
Open

arvindvenkataramani wants to merge 1 commit into
yashhere:mainfrom
arvindvenkataramani:feat/cors-support

Conversation

@arvindvenkataramani

Copy link
Copy Markdown

What this does

Adds configurable CORS support to the FastAPI app. CORS is disabled by default — it only activates when PARAKEET_CORS_ORIGINS is set.

Why

When running this service as part of a larger system (e.g. behind a local dashboard or UI that makes requests from the browser), CORS headers are required. Without them, browser requests are blocked.

I ran into this while integrating parakeet-mlx-fastapi into a custom home automation project. The fix that comes to mind is just allow_origins=["*"], but that's insecure by default — so this adds proper configurability instead.

How to use

Set the PARAKEET_CORS_ORIGINS environment variable to a comma-separated list of allowed origins before starting the server:

PARAKEET_CORS_ORIGINS=http://localhost:3000,https://myapp.example.com parakeet-server

Or in a .env file:

PARAKEET_CORS_ORIGINS=http://localhost:3000

If the variable is unset or empty, no CORSMiddleware is added and the service behaves exactly as before.

Changes

  • config.py — reads PARAKEET_CORS_ORIGINS into CORS_ORIGINS: list[str], following the existing PARAKEET_WORKERS pattern
  • main.py — imports CORSMiddleware and conditionally adds it in create_app() when CORS_ORIGINS is non-empty

This has been reviewed and tested in a real integration against a local dashboard.

- config.py: read PARAKEET_CORS_ORIGINS (comma-separated origins) into CORS_ORIGINS list
- main.py: conditionally add CORSMiddleware when CORS_ORIGINS is set

CORS is disabled by default (secure by default). To enable, set the
environment variable to a comma-separated list of allowed origins:

  PARAKEET_CORS_ORIGINS=http://localhost:3000,https://myapp.example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant