Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viewer: Add HTML helper to view nodes #458

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pymongo.errors import DuplicateKeyError
from fastapi_users import FastAPIUsers
from beanie import PydanticObjectId
from kernelci.api.models import (

Check failure on line 30 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
PublishEvent,
Expand Down Expand Up @@ -714,6 +714,26 @@
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
Loading