Spaces:
Running
Running
Miyu Horiuchi commited on
Commit ·
e2d32ba
1
Parent(s): 3b4d471
Fix Space root health checks
Browse files- api/main.py +10 -2
api/main.py
CHANGED
|
@@ -23,7 +23,7 @@ import requests
|
|
| 23 |
from fastapi import FastAPI, HTTPException
|
| 24 |
from fastapi.middleware.cors import CORSMiddleware
|
| 25 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 26 |
-
from fastapi.responses import FileResponse
|
| 27 |
from fastapi.staticfiles import StaticFiles
|
| 28 |
from pydantic import BaseModel
|
| 29 |
|
|
@@ -201,9 +201,13 @@ def _safe_str(v, default=None):
|
|
| 201 |
|
| 202 |
|
| 203 |
@app.get("/api/catalog")
|
| 204 |
-
def catalog():
|
| 205 |
"""Return the full uncultured catalog as a list of dicts. Gzipped by middleware."""
|
| 206 |
df = _state["catalog"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
rows = []
|
| 208 |
for _, m in df.iterrows():
|
| 209 |
rows.append({
|
|
@@ -334,6 +338,10 @@ WEB_BUILD = ROOT / "web" / "dist"
|
|
| 334 |
if WEB_BUILD.exists():
|
| 335 |
app.mount("/assets", StaticFiles(directory=WEB_BUILD / "assets"), name="assets")
|
| 336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
@app.get("/")
|
| 338 |
def root():
|
| 339 |
return FileResponse(WEB_BUILD / "index.html")
|
|
|
|
| 23 |
from fastapi import FastAPI, HTTPException
|
| 24 |
from fastapi.middleware.cors import CORSMiddleware
|
| 25 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 26 |
+
from fastapi.responses import FileResponse, Response
|
| 27 |
from fastapi.staticfiles import StaticFiles
|
| 28 |
from pydantic import BaseModel
|
| 29 |
|
|
|
|
| 201 |
|
| 202 |
|
| 203 |
@app.get("/api/catalog")
|
| 204 |
+
def catalog(limit: int | None = None):
|
| 205 |
"""Return the full uncultured catalog as a list of dicts. Gzipped by middleware."""
|
| 206 |
df = _state["catalog"]
|
| 207 |
+
if limit is not None:
|
| 208 |
+
if limit < 1:
|
| 209 |
+
raise HTTPException(status_code=400, detail="limit must be >= 1")
|
| 210 |
+
df = df.head(limit)
|
| 211 |
rows = []
|
| 212 |
for _, m in df.iterrows():
|
| 213 |
rows.append({
|
|
|
|
| 338 |
if WEB_BUILD.exists():
|
| 339 |
app.mount("/assets", StaticFiles(directory=WEB_BUILD / "assets"), name="assets")
|
| 340 |
|
| 341 |
+
@app.head("/")
|
| 342 |
+
def root_head():
|
| 343 |
+
return Response(status_code=200)
|
| 344 |
+
|
| 345 |
@app.get("/")
|
| 346 |
def root():
|
| 347 |
return FileResponse(WEB_BUILD / "index.html")
|