Skip to content

Commit dac2746

Browse files
committed
fix(vercel): keep a single ASGI entrypoint so the preset cannot build an uninstalled second function
1 parent 29d73bc commit dac2746

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \
5555
# Single worker by default: the process holds a database pool and, when the
5656
# local models are installed, model weights in memory. Scale with replicas, not
5757
# with workers.
58-
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT} --workers 1 --timeout-keep-alive 75"]
58+
CMD ["sh", "-c", "uvicorn app.main:create_app --factory --host 0.0.0.0 --port ${PORT} --workers 1 --timeout-keep-alive 75"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Without Docker:
222222
```bash
223223
uv venv && uv pip install -r requirements.txt -r requirements-local.txt
224224
alembic upgrade head
225-
uvicorn app.main:app --reload
225+
uvicorn app.main:create_app --factory --reload
226226
```
227227

228228
> Already running Postgres on 5432? Set `POSTGRES_PORT=5433` in `.env` and update `DATABASE_URL`

app/main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,16 @@ async def unhandled(request: Request, exc: Exception) -> JSONResponse:
8888
return app
8989

9090

91-
app = create_app()
91+
# Deliberately no module-level `app = create_app()` here.
92+
#
93+
# Vercel's FastAPI preset scans the repo for a module-level ASGI instance and
94+
# builds whatever it finds as the function. With one in this module *and* one in
95+
# api/index.py it picked this file, while the dependency install was scoped to
96+
# the entrypoint declared in vercel.json — so the deployed function ran without
97+
# fastapi installed and died with ModuleNotFoundError at cold start.
98+
#
99+
# There is now exactly one ASGI callable in the repo, at api/index.py. Anything
100+
# that needs an instance builds one from the factory:
101+
#
102+
# uvicorn app.main:create_app --factory
103+

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ services:
5656
- hf_cache:/home/documind/.cache/huggingface
5757
command: >
5858
sh -c "alembic upgrade head &&
59-
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload"
59+
uvicorn app.main:create_app --factory --host 0.0.0.0 --port 8000 --reload"
6060
6161
# Optional second vector store, for the pgvector/Qdrant comparison.
6262
# docker compose --profile qdrant up

0 commit comments

Comments
 (0)