Skip to content

Commit

Permalink
viewer: Add HTML helper to view nodes
Browse files Browse the repository at this point in the history
This is PoC of API viewer for development purposes.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Feb 19, 2024
1 parent 628a6d6 commit 70bc3cf
Show file tree
Hide file tree
Showing 2 changed files with 590 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down
Loading

0 comments on commit 70bc3cf

Please sign in to comment.