|
1 | 1 | """Vercel serverless entrypoint. |
2 | 2 |
|
3 | | -Vercel's @vercel/python runtime looks for a module-level ASGI callable named |
4 | | -`app`. Everything else in this file exists to make the repo root importable, |
5 | | -since Vercel executes this module from inside api/ rather than the project root. |
| 3 | +Vercel's Python runtime looks for a module-level ASGI callable named `app`. |
| 4 | +Everything else here exists because this module is executed from inside api/ |
| 5 | +rather than the project root, so the repo root has to be put on sys.path before |
| 6 | +`app` is importable. |
6 | 7 | """ |
7 | 8 |
|
8 | 9 | import os |
9 | 10 | import sys |
10 | 11 |
|
11 | | -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 12 | +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 13 | +sys.path.insert(0, ROOT) |
12 | 14 |
|
13 | | -from app.main import create_app # noqa: E402 |
| 15 | +try: |
| 16 | + from app.main import create_app |
| 17 | +except ModuleNotFoundError as exc: # pragma: no cover - deployment diagnostics |
| 18 | + # A missing package here is almost always a packaging problem, not a code |
| 19 | + # one: something excluded `app/` or a subpackage from the bundle. The raw |
| 20 | + # traceback surfaces only as FUNCTION_INVOCATION_FAILED with the build |
| 21 | + # reporting success, which sends you looking in entirely the wrong place — |
| 22 | + # so say what is actually on disk. |
| 23 | + present = sorted(p for p in os.listdir(ROOT) if not p.startswith(".")) |
| 24 | + raise RuntimeError( |
| 25 | + f"Could not import {exc.name!r} from the deployment bundle. " |
| 26 | + f"Project root {ROOT} contains: {present}. " |
| 27 | + "If 'app' is absent or incomplete, check .vercelignore — its patterns " |
| 28 | + "use gitignore semantics, so an unanchored directory name matches at " |
| 29 | + "every depth." |
| 30 | + ) from exc |
14 | 31 |
|
15 | 32 | app = create_app() |
0 commit comments