Spaces:
Runtime error
Runtime error
Commit ·
b759462
1
Parent(s): 4e293c6
fix: 恢复前端 API 密钥端点供内置 Web UI 使用
Browse files- app/main.py +16 -1
app/main.py
CHANGED
|
@@ -105,13 +105,28 @@ def create_app() -> FastAPI:
|
|
| 105 |
app.include_router(images_router, tags=["Images"])
|
| 106 |
|
| 107 |
# Rate limiter metrics endpoint
|
| 108 |
-
from fastapi.responses import ORJSONResponse
|
| 109 |
|
| 110 |
@app.get("/metrics/rate-limiter", tags=["Metrics"], include_in_schema=False)
|
| 111 |
async def rate_limiter_metrics():
|
| 112 |
"""Get rate limiter metrics for monitoring."""
|
| 113 |
metrics = await get_rate_limiter_metrics()
|
| 114 |
return ORJSONResponse(content=metrics)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
# Mount static files (frontend)
|
| 117 |
# This must be the last mount to avoid overriding other routes
|
|
|
|
| 105 |
app.include_router(images_router, tags=["Images"])
|
| 106 |
|
| 107 |
# Rate limiter metrics endpoint
|
| 108 |
+
from fastapi.responses import ORJSONResponse, Response
|
| 109 |
|
| 110 |
@app.get("/metrics/rate-limiter", tags=["Metrics"], include_in_schema=False)
|
| 111 |
async def rate_limiter_metrics():
|
| 112 |
"""Get rate limiter metrics for monitoring."""
|
| 113 |
metrics = await get_rate_limiter_metrics()
|
| 114 |
return ORJSONResponse(content=metrics)
|
| 115 |
+
|
| 116 |
+
# Frontend config endpoint (for built-in web UI only)
|
| 117 |
+
# This is safe because:
|
| 118 |
+
# 1. Only serves the built-in frontend
|
| 119 |
+
# 2. Rate limiter protects against abuse
|
| 120 |
+
# 3. Should not be exposed to public internet
|
| 121 |
+
@app.get("/auth/config.js", tags=["Auth"])
|
| 122 |
+
async def get_frontend_config():
|
| 123 |
+
"""Provide API key to built-in frontend."""
|
| 124 |
+
config_js = f"""
|
| 125 |
+
window.GEMINI_CONFIG = {{
|
| 126 |
+
API_KEY: "{g_config.server.api_key or ''}"
|
| 127 |
+
}};
|
| 128 |
+
"""
|
| 129 |
+
return Response(content=config_js, media_type="application/javascript")
|
| 130 |
|
| 131 |
# Mount static files (frontend)
|
| 132 |
# This must be the last mount to avoid overriding other routes
|