|
12 | 12 | from datetime import datetime |
13 | 13 | from typing import Optional, Dict, Any, List |
14 | 14 | from fastapi import FastAPI, HTTPException |
15 | | -from fastapi.responses import JSONResponse |
| 15 | +from fastapi.responses import JSONResponse, FileResponse |
| 16 | +from fastapi.staticfiles import StaticFiles |
16 | 17 | import uvicorn |
17 | 18 |
|
18 | 19 | app = FastAPI(title="ICRN Kernel Manager API", version="1.0.0") |
|
21 | 22 | COLLATED_MANIFESTS_PATH = os.getenv("COLLATED_MANIFESTS_PATH", "/app/data/collated_manifests.json") |
22 | 23 | PACKAGE_INDEX_PATH = os.getenv("PACKAGE_INDEX_PATH", "/app/data/package_index.json") |
23 | 24 | KERNEL_ROOT = os.getenv("KERNEL_ROOT", "/app/data") |
| 25 | +STATIC_DIR = Path("/app/static") |
24 | 26 | DATA_DIR = Path(COLLATED_MANIFESTS_PATH).parent |
25 | 27 | DATA_DIR.mkdir(parents=True, exist_ok=True) |
26 | 28 |
|
| 29 | +# Mount static files directory |
| 30 | +if STATIC_DIR.exists(): |
| 31 | + app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static") |
| 32 | + |
27 | 33 | # Global variable to store loaded data |
28 | 34 | collated_manifests: Optional[Dict[str, Any]] = None |
29 | 35 | package_index: Optional[Dict[str, Any]] = None |
@@ -128,16 +134,20 @@ async def startup_event(): |
128 | 134 | @app.get("/") |
129 | 135 | async def root(): |
130 | 136 | """ |
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. |
133 | 138 | """ |
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 | + } |
141 | 151 |
|
142 | 152 |
|
143 | 153 | @app.get("/health") |
|
0 commit comments