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

Fix Kedro-viz embedded as an IFrame #1658

Merged
merged 6 commits into from
Dec 5, 2023
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
2 changes: 2 additions & 0 deletions demo-project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ COPY . /code
RUN pip install --no-cache-dir --upgrade -r /code/src/docker_requirements.txt

CMD ["kedro", "viz", "--host", "0.0.0.0", "--port", "4141", "--no-browser"]

ENV ADD_SECURITY_HEADERS=true
16 changes: 9 additions & 7 deletions package/kedro_viz/api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This data could either come from a real Kedro project or a file.
"""
import json
import os
import time
from pathlib import Path

Expand All @@ -21,8 +22,6 @@

_HTML_DIR = Path(__file__).parent.parent.absolute() / "html"

secure_headers = secure.Secure()


def _create_etag() -> str:
"""Generate the current timestamp to use as etag."""
Expand All @@ -37,11 +36,14 @@ def _create_base_api_app() -> FastAPI:
default_response_class=EnhancedORJSONResponse,
)

@app.middleware("http")
async def set_secure_headers(request, call_next):
response = await call_next(request)
secure_headers.framework.fastapi(response)
return response
if os.getenv("ADD_SECURITY_HEADERS", "").lower() == "true": # pragma: no cover
secure_headers = secure.Secure()

@app.middleware("http")
async def set_secure_headers(request, call_next):
response = await call_next(request)
secure_headers.framework.fastapi(response)
return response

return app

Expand Down