fix: Serve dashboard independently of process working directory #47
|
|
@ -1,9 +1,12 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
DASHBOARD_FILE = Path(__file__).resolve().parent.parent / "frontend" / "index.html"
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_class=HTMLResponse)
|
@router.get("/", response_class=HTMLResponse)
|
||||||
async def dashboard() -> str:
|
async def dashboard() -> str:
|
||||||
return open("frontend/index.html").read()
|
return DASHBOARD_FILE.read_text()
|
||||||
|
|
|
||||||
12
tests/test_views.py
Normal file
12
tests/test_views.py
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from src.views import dashboard
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_dashboard_renders_outside_repository_working_directory(monkeypatch, tmp_path):
|
||||||
|
monkeypatch.chdir(tmp_path)
|
||||||
|
|
||||||
|
html = await dashboard()
|
||||||
|
|
||||||
|
assert "Stackchain Dashboard" in html
|
||||||
Loading…
Reference in New Issue
Block a user