Skip to content

Commit 70bc3cf

Browse files
committed
viewer: Add HTML helper to view nodes
This is PoC of API viewer for development purposes. Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent 628a6d6 commit 70bc3cf

File tree

2 files changed

+590
-0
lines changed

2 files changed

+590
-0
lines changed

api/main.py

+20
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,26 @@ async def stats(user: User = Depends(get_current_superuser)):
714714
return await pubsub.subscription_stats()
715715

716716

717+
@app.get('/viewer')
718+
async def viewer():
719+
"""Serve simple HTML page to view the API /static/viewer.html
720+
Set various no-cache tag we might update it often"""
721+
mod_root = os.path.dirname(os.path.abspath(__file__))
722+
# truncate the last part of the path to get the root of the module
723+
# We need to install templates UNDER api package
724+
mod_root = os.path.dirname(mod_root)
725+
viewer_path = os.path.join(mod_root, 'templates', 'viewer.html')
726+
with open(viewer_path, 'r', encoding='utf-8') as file:
727+
# set header to text/html and no-cache stuff
728+
hdr = {
729+
'Content-Type': 'text/html',
730+
'Cache-Control': 'no-cache, no-store, must-revalidate',
731+
'Pragma': 'no-cache',
732+
'Expires': '0'
733+
}
734+
return PlainTextResponse(file.read(), headers=hdr)
735+
736+
717737
versioned_app = VersionedFastAPI(
718738
app,
719739
version_format='{major}',

0 commit comments

Comments
 (0)