Bundle FastAPI backend into Next.js Docker container

The Next.js app was proxying /api/* to the old Flask/FastAPI server
at legal-ai.nautilus.marcusgroup.org. When that server went down,
the Next.js app's API calls failed with 503.

Now both services run in the same container:
- FastAPI (uvicorn) on :8000 — the API backend
- Next.js (node) on :3000 — proxies /api/* to localhost:8000

Changes:
- Dockerfile: multi-stage build with Python 3.12 + Node.js
- next.config.ts: default proxy target is now 127.0.0.1:8000
- start.sh: launches uvicorn in background + node in foreground
- pyproject.toml: add fastapi + uvicorn as explicit deps

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 14:33:52 +00:00
parent cc50f0ffde
commit 94bc66d7c1
5 changed files with 65 additions and 19 deletions

View File

@@ -1,17 +1,14 @@
import type { NextConfig } from "next";
/**
* Staging config — proxies /api/* and /openapi.json to the production FastAPI
* at legal-ai.nautilus.marcusgroup.org. This lets the new Next.js UI call the
* existing backend without CORS and without running a second FastAPI instance.
*
* When the rewrite branch is cut over to production, set NEXT_PUBLIC_API_BASE_URL
* and/or move the FastAPI in front of this app via traefik routing.
* Proxies /api/* and /openapi.json to the FastAPI backend.
* In Docker both processes run in the same container, so the default
* target is http://127.0.0.1:8000. Override with NEXT_PUBLIC_API_ORIGIN
* if the backend lives elsewhere (e.g. during local dev).
*/
const API_ORIGIN =
process.env.NEXT_PUBLIC_API_ORIGIN ??
"https://legal-ai.nautilus.marcusgroup.org";
process.env.NEXT_PUBLIC_API_ORIGIN ?? "http://127.0.0.1:8000";
const nextConfig: NextConfig = {
output: "standalone",