-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.py
More file actions
36 lines (33 loc) · 1.24 KB
/
Copy pathdocs.py
File metadata and controls
36 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Serve documentation markdown files via API for easy linking from UI
"""
from fastapi import APIRouter, HTTPException, Response
from pathlib import Path
import structlog
logger = structlog.get_logger()
router = APIRouter(prefix="/docs", tags=["documentation"])
DOCS_DIR = Path("/app/enterprise/docs")
@router.get("/{name}")
async def get_doc(name: str):
try:
safe = ''.join(c for c in name if c.isalnum() or c in ('-', '_'))
mapping = {
"install": "INSTALL.md",
"requirements": "REQUIREMENTS.md",
"ssvc": "SSVC.md",
"roadmap": "ROADMAP.md",
"architecture": "ARCHITECTURE.md",
}
filename = mapping.get(safe, None)
if not filename:
raise HTTPException(status_code=404, detail="Document not found")
path = DOCS_DIR / filename
if not path.exists():
raise HTTPException(status_code=404, detail="Document missing")
content = path.read_text(encoding='utf-8')
return Response(content=content, media_type="text/markdown; charset=utf-8")
except HTTPException:
raise
except Exception as e:
logger.error(f"get_doc failed: {e}")
raise HTTPException(status_code=500, detail=str(e))