Skip to content

[BUG]: No CORS middleware on FastAPI app — frontend requests blocked by browser #415

@abhishek-8081

Description

@abhishek-8081

⚡️ Describe the Bug

api/main.py has no CORS middleware configured. Any request made from a browser-based frontend (React, vanilla JS, etc.) running on a different origin gets blocked with a CORS policy error. The API works fine from curl or Postman, but not from any browser.

👣 Steps to Reproduce

  1. Start the API with uvicorn api.main:app --reload (runs on port 8000)
  2. Open a frontend app on a different port (e.g. http://localhost:3000)
  3. Try calling any endpoint like POST /forms/fill via fetch() or axios
  4. Browser console shows: Access to fetch has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present

📉 Expected Behavior

The API should include CORS middleware so that frontend apps running on different origins can communicate with it without being blocked by the browser.

🖥️ Environment Information

  • OS: macOS
  • Docker/Compose Version: Docker 27.x / Compose v2
  • Ollama Model used: N/A (this is an API-level config issue)

📸 Screenshots/Logs

Current api/main.py — no CORS setup at all:

from fastapi import FastAPI
from api.routes import templates, forms

app = FastAPI()

app.include_router(templates.router)
app.include_router(forms.router)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions