Fix production deployment: replace serve with nginx reverse proxy
Frontend container now uses nginx to serve static files and proxy /api/* requests to the backend container internally, eliminating the hardcoded localhost:8000 build-time URL that caused "Network error" on any non-local server. CORS origins are also configurable via ALLOWED_ORIGINS env var. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from sqlalchemy import text
|
||||
@@ -9,9 +11,15 @@ Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI(title="BTC Portfolio API")
|
||||
|
||||
_raw_origins = os.environ.get(
|
||||
"ALLOWED_ORIGINS",
|
||||
"http://localhost:3000,http://localhost:3001",
|
||||
)
|
||||
allowed_origins = [o.strip() for o in _raw_origins.split(",") if o.strip()]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:3000", "http://localhost:3001"],
|
||||
allow_origins=allowed_origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||
allow_headers=["Content-Type", "Authorization"],
|
||||
|
||||
Reference in New Issue
Block a user