This commit is contained in:
@@ -397,6 +397,18 @@ def page_to_dict(page: ContentPage) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def server_diagnostics() -> dict[str, Any]:
|
||||
pages = list_pages()
|
||||
return {
|
||||
"root": ROOT.as_posix(),
|
||||
"cwd": Path.cwd().as_posix(),
|
||||
"executable": sys.executable,
|
||||
"pid": os.getpid(),
|
||||
"pageCount": len(pages),
|
||||
"firstPage": pages[0]["path"] if pages else "",
|
||||
}
|
||||
|
||||
|
||||
def list_pages() -> list[dict[str, Any]]:
|
||||
pages = []
|
||||
org_paths = []
|
||||
@@ -1355,6 +1367,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
except Exception as exc:
|
||||
self.send_json({"error": str(exc)}, HTTPStatus.INTERNAL_SERVER_ERROR)
|
||||
return
|
||||
if parsed.path == "/api/diagnostics":
|
||||
try:
|
||||
self.send_json(server_diagnostics())
|
||||
except Exception as exc:
|
||||
self.send_json({"error": str(exc)}, HTTPStatus.INTERNAL_SERVER_ERROR)
|
||||
return
|
||||
if parsed.path == "/api/page":
|
||||
query = parse_qs(parsed.query)
|
||||
try:
|
||||
@@ -1408,8 +1426,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
def main() -> None:
|
||||
port = int(os.environ.get("AUTHOR_PORT", "8765"))
|
||||
server = ThreadingHTTPServer(("127.0.0.1", port), Handler)
|
||||
page_count = len(list_pages())
|
||||
print(f"Authoring UI running at http://127.0.0.1:{port}")
|
||||
print(f"Content root: {ROOT}")
|
||||
print(f"Editable pages: {page_count}")
|
||||
if page_count == 0:
|
||||
print("WARNING: no editable pages were found. Check AUTHOR_ROOT and the launch directory.")
|
||||
print("Press Ctrl-C to stop.")
|
||||
try:
|
||||
server.serve_forever()
|
||||
|
||||
Reference in New Issue
Block a user