Skip to content

Fix Vercel FastAPI entrypoint#25

Merged
gitgrahamdunn merged 1 commit intomainfrom
codex/fix-vercel-fastapi-entrypoint
Feb 18, 2026
Merged

Fix Vercel FastAPI entrypoint#25
gitgrahamdunn merged 1 commit intomainfrom
codex/fix-vercel-fastapi-entrypoint

Conversation

@gitgrahamdunn
Copy link
Copy Markdown
Owner

Motivation

  • Vercel expects a module that exports a FastAPI instance named app at the project root for serverless functions, and the backend was crashing because no compatible entrypoint was present.
  • Provide a minimal shim that re-uses the existing application object without duplicating business logic.

Description

  • Add backend/index.py which attempts to import the existing FastAPI app by trying these paths in order: from app.main import app, from main import app, from app.server import app, and from server import app.
  • Use importlib.import_module to dynamically load the first successful module and bind its app into this entrypoint.
  • If none of the tried module paths resolve, raise a clear ImportError that lists all attempted import targets.
  • No business logic, routes, or existing modules were modified; only the minimal entrypoint file was added.

Testing

  • Ran backend unit tests with cd backend && pytest -q and all tests passed: 18 passed, 2 warnings.
  • Performed a dynamic import validation with Python by importing the new index module and verifying type(index.app) is FastAPI, which succeeded.

Codex Task

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gitplant Ready Ready Preview, Comment Feb 18, 2026 9:42pm
gitplant-backend Ready Ready Preview, Comment Feb 18, 2026 9:42pm
gitplant-oggy Ready Ready Preview, Comment Feb 18, 2026 9:42pm

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a94abbd73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/index.py
try:
app = import_module(_module_path).app
break
except (ImportError, AttributeError):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid swallowing import errors from valid app module

The broad except (ImportError, AttributeError) treats any ImportError raised during import_module(_module_path) as a missing module path, so if app.main exists but one of its own imports fails (for example, a missing dependency or typo in app.main), the real exception is suppressed and replaced with the generic "Could not import FastAPI app" error. This makes production failures much harder to diagnose and can also cause the loop to try unintended fallbacks; only missing-target-module cases should be swallowed while other import failures should be re-raised.

Useful? React with 👍 / 👎.

@gitgrahamdunn gitgrahamdunn merged commit 21003ac into main Feb 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant