From 70bc3cf83e8087bafae03c5438dac839117bf15e Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Thu, 25 Jan 2024 04:15:42 +0200 Subject: [PATCH] viewer: Add HTML helper to view nodes This is PoC of API viewer for development purposes. Signed-off-by: Denys Fedoryshchenko --- api/main.py | 20 ++ templates/viewer.html | 570 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 590 insertions(+) create mode 100644 templates/viewer.html diff --git a/api/main.py b/api/main.py index 27c9690f..51375e53 100644 --- a/api/main.py +++ b/api/main.py @@ -714,6 +714,26 @@ async def stats(user: User = Depends(get_current_superuser)): return await pubsub.subscription_stats() +@app.get('/viewer') +async def viewer(): + """Serve simple HTML page to view the API /static/viewer.html + Set various no-cache tag we might update it often""" + mod_root = os.path.dirname(os.path.abspath(__file__)) + # truncate the last part of the path to get the root of the module + # We need to install templates UNDER api package + mod_root = os.path.dirname(mod_root) + viewer_path = os.path.join(mod_root, 'templates', 'viewer.html') + with open(viewer_path, 'r', encoding='utf-8') as file: + # set header to text/html and no-cache stuff + hdr = { + 'Content-Type': 'text/html', + 'Cache-Control': 'no-cache, no-store, must-revalidate', + 'Pragma': 'no-cache', + 'Expires': '0' + } + return PlainTextResponse(file.read(), headers=hdr) + + versioned_app = VersionedFastAPI( app, version_format='{major}', diff --git a/templates/viewer.html b/templates/viewer.html new file mode 100644 index 00000000..207d20bc --- /dev/null +++ b/templates/viewer.html @@ -0,0 +1,570 @@ + + + + KernelCIv2 API Viewer + + + + + + + +
+
+
+
+ + \ No newline at end of file