|
@@ -6,9 +6,11 @@ from typing import Optional, Callable, Any
|
|
|
import datetime
|
|
|
|
|
|
from pydantic import BaseModel, BaseSettings, Field
|
|
|
-from fastapi import FastAPI, Depends, HTTPException, status, Response
|
|
|
+from fastapi import FastAPI, Depends, HTTPException, status, Response, Request
|
|
|
+from fastapi.responses import HTMLResponse
|
|
|
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
+from fastapi.templating import Jinja2Templates
|
|
|
|
|
|
|
|
|
class VariableModel(BaseModel):
|
|
@@ -50,6 +52,7 @@ class Settings(BaseSettings):
|
|
|
app = FastAPI()
|
|
|
settings = Settings()
|
|
|
security = HTTPBasic()
|
|
|
+templates = Jinja2Templates(directory="templates")
|
|
|
|
|
|
|
|
|
app.add_middleware(
|
|
@@ -144,3 +147,9 @@ async def export_prometheus() -> str:
|
|
|
variables.append(("squeow_time_since_last_seen", int(time_since_last_seen)))
|
|
|
text = "".join(f"{k} {v}\n" for k, v in variables)
|
|
|
return Response(text, media_type="text/plain")
|
|
|
+
|
|
|
+
|
|
|
+@app.get("/", response_class=HTMLResponse)
|
|
|
+async def get_page_index(request: Request):
|
|
|
+ return templates.TemplateResponse("index.html",
|
|
|
+ dict(request=request, variables=settings.variables))
|