From 84eb60f73d3e92c412f9d95a8d8888d64f3ef9ca Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Thu, 1 Dec 2022 15:18:50 +1100 Subject: [PATCH] Allow workshop instructions on different host to send Javascript messages to dashboard. --- .../opt/gateway/src/backend/views/dashboard-page.pug | 1 + .../opt/gateway/src/frontend/scripts/eduk8s.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/workshop-images/base-environment/opt/gateway/src/backend/views/dashboard-page.pug b/workshop-images/base-environment/opt/gateway/src/backend/views/dashboard-page.pug index 09fba896..d1186eb6 100644 --- a/workshop-images/base-environment/opt/gateway/src/backend/views/dashboard-page.pug +++ b/workshop-images/base-environment/opt/gateway/src/backend/views/dashboard-page.pug @@ -24,6 +24,7 @@ html.no-scrolling data-ingress-protocol=config.ingress_protocol, data-ingress-port-suffix=config.ingress_port_suffix, data-terminal-layout=config.terminal_layout, + data-workshop-url=config.workshop_url, data-workshop-ready=`${workshop_ready}`, data-time-started=`${time_started}`, data-page-hits=page_hits) diff --git a/workshop-images/base-environment/opt/gateway/src/frontend/scripts/eduk8s.ts b/workshop-images/base-environment/opt/gateway/src/frontend/scripts/eduk8s.ts index 6cbd3b35..fca4448a 100644 --- a/workshop-images/base-environment/opt/gateway/src/frontend/scripts/eduk8s.ts +++ b/workshop-images/base-environment/opt/gateway/src/frontend/scripts/eduk8s.ts @@ -1368,6 +1368,17 @@ class Dashboard { let result = false + let $body = $("body") + let workshop_url = $body.data("workshop-url") + + if (workshop_url && workshop_url.match(/^https?:/)) { + let url = new URL(workshop_url) + + if (origin == url.origin) { + result = true + } + } + $(".dashboard-iframe").each((index: number, element: HTMLElement) => { let src = element.dataset["src"]