Skip to content

Commit dcc5c94

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 9f40ec4 commit dcc5c94

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
@@ -733,6 +733,26 @@ async def stats(user: User = Depends(get_current_superuser)):
733733
return await pubsub.subscription_stats()
734734

735735

736+
@app.get('/viewer')
737+
async def viewer():
738+
"""Serve simple HTML page to view the API /static/viewer.html
739+
Set various no-cache tag we might update it often"""
740+
mod_root = os.path.dirname(os.path.abspath(__file__))
741+
# truncate the last part of the path to get the root of the module
742+
# We need to install templates UNDER api package
743+
mod_root = os.path.dirname(mod_root)
744+
viewer_path = os.path.join(mod_root, 'templates', 'viewer.html')
745+
with open(viewer_path, 'r', encoding='utf-8') as file:
746+
# set header to text/html and no-cache stuff
747+
hdr = {
748+
'Content-Type': 'text/html',
749+
'Cache-Control': 'no-cache, no-store, must-revalidate',
750+
'Pragma': 'no-cache',
751+
'Expires': '0'
752+
}
753+
return PlainTextResponse(file.read(), headers=hdr)
754+
755+
736756
versioned_app = VersionedFastAPI(
737757
app,
738758
version_format='{major}',

0 commit comments

Comments
 (0)