From be16c3c05705687bb3795e70dc620a6388ceabaa Mon Sep 17 00:00:00 2001 From: dominikn Date: Wed, 18 Oct 2023 15:51:45 +0200 Subject: [PATCH] new envs for controlling cache, and ro mode --- Caddyfile | 13 ++++++++++++- Dockerfile | 7 ++++++- README.md | 2 ++ demo/compose.yaml | 2 ++ disable_cache.js | 2 ++ disable_interaction.js | 14 ++++++++++++++ entrypoint.sh | 26 ++++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 disable_cache.js create mode 100644 disable_interaction.js diff --git a/Caddyfile b/Caddyfile index d78235c..48d3977 100644 --- a/Caddyfile +++ b/Caddyfile @@ -4,7 +4,18 @@ root * /src - redir /ui /?ds={$DS_TYPE}&ds.url=ws%3A%2F%2F{http.request.host}%3A{$DS_PORT} + # Handle requests from Husarnet IPv6 clients + @ipv6Client { + expression {http.request.host}.startsWith("fc94") + } + handle @ipv6Client { + redir /ui /?ds={$DS_TYPE}&ds.url=ws%3A%2F%2F%5B{http.request.host}%5D%3A{$DS_PORT} + } + + # Handle all other requests (from non-IPv6 clients) + handle { + redir /ui /?ds={$DS_TYPE}&ds.url=ws%3A%2F%2F{http.request.host}%3A{$DS_PORT} + } templates { mime "application/json" "text/plain" "text/html" diff --git a/Dockerfile b/Dockerfile index 8760d00..68f7430 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,9 @@ WORKDIR /src COPY --from=foxglove_build /src . COPY FoxgloveDefaultLayout.json /foxglove/default-layout.json +COPY disable_cache.js / +COPY disable_interaction.js / + COPY Caddyfile /etc/caddy/ COPY entrypoint.sh / @@ -67,9 +70,11 @@ EXPOSE 8080 ENV DS_TYPE=rosbridge-websocket ENV DS_PORT=9090 ENV UI_PORT=8080 +ENV DISABLE_INTERACTION=false +ENV DISABLE_CACHE=true # replace file:///ros2_ws with http://{{.Host}}:UI_PORT/ros2_ws RUN sed -i 's|file:///ros2_ws|http://{{.Host}}:{{env "UI_PORT"}}/ros2_ws|g' /src/rosbot_xl.urdf /src/rosbot.urdf /src/panther.urdf -ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"] diff --git a/README.md b/README.md index f74ca11..d5b936b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Foxglove docker images customized for running directly on the robot | `DS_TYPE` | `rosbridge-websocket` | Data source type. Possible values: `rosbridge-websocket` or `foxglove-websocket` | | `DS_PORT` | `9090` | Data source port | | `UI_PORT` | `8080` | User interface port | +| `DISABLE_CACHE` | `true` | Clear local storage in browser on page reload | +| `DISABLE_INTERACTION` | `false` | Make the UI read only | ## Quick Start diff --git a/demo/compose.yaml b/demo/compose.yaml index 7a5892e..b459f31 100644 --- a/demo/compose.yaml +++ b/demo/compose.yaml @@ -12,6 +12,8 @@ services: - DS_TYPE=rosbridge-websocket - DS_PORT=9090 - UI_PORT=8080 + - DISABLE_CACHE=true + - DISABLE_INTERACTION=false rosbridge: image: husarion/rosbridge-server:humble diff --git a/disable_cache.js b/disable_cache.js new file mode 100644 index 0000000..6c27dfa --- /dev/null +++ b/disable_cache.js @@ -0,0 +1,2 @@ +localStorage.clear(); +sessionStorage.clear(); diff --git a/disable_interaction.js b/disable_interaction.js new file mode 100644 index 0000000..13ab8b0 --- /dev/null +++ b/disable_interaction.js @@ -0,0 +1,14 @@ +document.addEventListener("DOMContentLoaded", function() { + var blocker = document.createElement("div"); + + blocker.style.position = "fixed"; + blocker.style.top = "0"; + blocker.style.left = "0"; + blocker.style.width = "100%"; + blocker.style.height = "100%"; + blocker.style.backgroundColor = "rgba(0, 0, 0, 0)"; + blocker.style.zIndex = "9999"; + blocker.style.pointerEvents = "all"; + + document.body.appendChild(blocker); +}); diff --git a/entrypoint.sh b/entrypoint.sh index a56821e..258da03 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,5 +10,31 @@ replace_pattern='/*FOXGLOVE_STUDIO_DEFAULT_LAYOUT_PLACEHOLDER*/' replace_value=$(cat /foxglove/remote-layout.json) echo "${index_html/"$replace_pattern"/$replace_value}" > index.html +# Check if ENABLE_SCRIPT1 is set to true +if [[ "$DISABLE_CACHE" == "true" ]]; then + echo "Cache is disabled" + # Read the content of script1.js into a variable + script1_content=$( + sed -i "s|
|\n&|" index.html +fi + +# Check if ENABLE_SCRIPT2 is set to true +if [[ "$DISABLE_INTERACTION" == "true" ]]; then + echo "Interaction is disabled" + # Read the content of script2.js into a variable + script2_content=$( + sed -i "s|
|\n&|" index.html +fi + # Continue executing the CMD exec "$@" \ No newline at end of file