Skip to content

Commit bbfeff4

Browse files
committed
chore: update .env.example and enhance FastAPI app for API key integration
- Added placeholder for API key in .env.example. - Modified axios client to retrieve API key from global configuration. - Updated FastAPI app to inject API key into the HTML response for client-side access.
1 parent 5752c9c commit bbfeff4

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ FLOW_DEFAULT_PROVIDER=yfinance
77
FLOW_BACKFILL_START_DATE=2005-01-01
88
FLOW_OVERLAP_DAYS=5
99

10-
FLOW_API_KEY=
11-
VITE_API_KEY=
10+
FLOW_API_KEY=your_api_key_here

frontend/src/api/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios';
22

3-
const apiKey = import.meta.env.VITE_API_KEY || '';
3+
const apiKey = (window as any).__FLOW_CONFIG__?.apiKey || '';
44

55
const apiClient = axios.create({
66
baseURL: import.meta.env.VITE_API_URL || '',

src/flow/api/app.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
from fastapi import Depends, FastAPI
55
from fastapi.staticfiles import StaticFiles
6-
from starlette.responses import FileResponse
6+
from starlette.responses import FileResponse, HTMLResponse
77

88
from flow.api.auth import require_api_key
99
from flow.api.routes.equity import router as equity_router
10+
from flow.config import settings
1011

1112
STATIC_DIR = Path(os.environ.get("FLOW_STATIC_DIR", "/app/static"))
1213

@@ -26,12 +27,19 @@ async def health():
2627
if STATIC_DIR.is_dir():
2728
app.mount("/assets", StaticFiles(directory=STATIC_DIR / "assets"), name="assets")
2829

30+
def _inject_config(html: str) -> str:
31+
import json
32+
config = json.dumps({"apiKey": settings.api_key})
33+
script = f"<script>window.__FLOW_CONFIG__={config};</script>"
34+
return html.replace("</head>", f"{script}\n</head>")
35+
2936
@app.get("/{full_path:path}")
3037
async def serve_spa(full_path: str):
3138
file_path = STATIC_DIR / full_path
3239
if file_path.is_file():
3340
return FileResponse(file_path)
34-
return FileResponse(STATIC_DIR / "index.html")
41+
index = (STATIC_DIR / "index.html").read_text()
42+
return HTMLResponse(_inject_config(index))
3543

3644
return app
3745

0 commit comments

Comments
 (0)