Skip to content

Commit 50209d4

Browse files
committed
updated the kernel service to serve static files directly
1 parent 7bcca11 commit 50209d4

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

web/kernel_service.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from datetime import datetime
1313
from typing import Optional, Dict, Any, List
1414
from fastapi import FastAPI, HTTPException
15-
from fastapi.responses import JSONResponse
15+
from fastapi.responses import JSONResponse, FileResponse
16+
from fastapi.staticfiles import StaticFiles
1617
import uvicorn
1718

1819
app = FastAPI(title="ICRN Kernel Manager API", version="1.0.0")
@@ -21,9 +22,14 @@
2122
COLLATED_MANIFESTS_PATH = os.getenv("COLLATED_MANIFESTS_PATH", "/app/data/collated_manifests.json")
2223
PACKAGE_INDEX_PATH = os.getenv("PACKAGE_INDEX_PATH", "/app/data/package_index.json")
2324
KERNEL_ROOT = os.getenv("KERNEL_ROOT", "/app/data")
25+
STATIC_DIR = Path("/app/static")
2426
DATA_DIR = Path(COLLATED_MANIFESTS_PATH).parent
2527
DATA_DIR.mkdir(parents=True, exist_ok=True)
2628

29+
# Mount static files directory
30+
if STATIC_DIR.exists():
31+
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
32+
2733
# Global variable to store loaded data
2834
collated_manifests: Optional[Dict[str, Any]] = None
2935
package_index: Optional[Dict[str, Any]] = None
@@ -128,16 +134,20 @@ async def startup_event():
128134
@app.get("/")
129135
async def root():
130136
"""
131-
Root endpoint - returns API information.
132-
Note: This service only reads pre-generated JSON files and does not perform indexing.
137+
Root endpoint - serves the web interface index.html.
133138
"""
134-
return {
135-
"service": "ICRN Kernel Manager API",
136-
"version": "1.0.0",
137-
"status": "running",
138-
"note": "This service reads pre-generated files only - no indexing performed",
139-
"last_refresh": last_refresh_time.isoformat() if last_refresh_time else None
140-
}
139+
index_path = STATIC_DIR / "index.html"
140+
if index_path.exists():
141+
return FileResponse(str(index_path))
142+
else:
143+
# Fallback to API info if index.html is missing
144+
return {
145+
"service": "ICRN Kernel Manager API",
146+
"version": "1.0.0",
147+
"status": "running",
148+
"note": "This service reads pre-generated files only - no indexing performed",
149+
"last_refresh": last_refresh_time.isoformat() if last_refresh_time else None
150+
}
141151

142152

143153
@app.get("/health")

0 commit comments

Comments
 (0)