Skip to content

[Fix] #99 — Consolidate duplicate FastAPI app instances and fix metrics route - #129

Open
adarsh-gautam-sys wants to merge 1 commit into
devloperdevesh:mainfrom
adarsh-gautam-sys:fix/issue-99-consolidate-fastapi-app
Open

[Fix] #99 — Consolidate duplicate FastAPI app instances and fix metrics route#129
adarsh-gautam-sys wants to merge 1 commit into
devloperdevesh:mainfrom
adarsh-gautam-sys:fix/issue-99-consolidate-fastapi-app

Conversation

@adarsh-gautam-sys

Copy link
Copy Markdown
Contributor

Summary

app/main.py created the FastAPI application instance multiple times, registered middlewares across different app instances, and defined the /metrics endpoint twice (once with authentication and once without it). Because Python executes the last definition, the unauthenticated version overrode the authenticated one, and middlewares registered to earlier app instances were lost. This PR consolidates the initialization into a single clean application structure and registers all middlewares and routers correctly.

Root Cause

Multiple FastAPI() instances and duplicate route definitions for /metrics in app/main.py caused routing conflicts, discarded middleware registrations, and security bypasses for the metrics endpoint.

Changes Made

  • Consolidated FastAPI app initialization to a single app = FastAPI(...) call.
  • Unified middleware configuration (CORS, Logging, Metrics) on the single app instance.
  • Registered routers (auth, tenants, documents, rag) cleanly.
  • Resolved incorrect/duplicate import paths for MetricsMiddleware, LoggingMiddleware, init_redis, and setup_tracing.
  • Consolidated /metrics endpoint to a single definition requiring admin authentication.

Related Issue

Closes #99

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

@adarsh-gautam-sys is attempting to deploy a commit to the devloperdevesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Multiple FastAPI app instances created and middleware initialized twice, causing duplicate route handlers

1 participant