Skip to content

Commit

Permalink
new envs for controlling cache, and ro mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Oct 18, 2023
1 parent d2087fe commit be16c3c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 /

Expand All @@ -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"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions demo/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions disable_cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localStorage.clear();
sessionStorage.clear();
14 changes: 14 additions & 0 deletions disable_interaction.js
Original file line number Diff line number Diff line change
@@ -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);
});
26 changes: 26 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$(</disable_cache.js)

# Escape certain characters in the content that might break sed
escaped_script1_content=$(echo "$script1_content" | sed 's/[&/\]/\\&/g')

# Use sed to insert the content into index.html just before </body>
sed -i "s|<div id=\"root\"></div>|<script>\n$(echo $escaped_script1_content)\n</script>\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=$(</disable_interaction.js)

# Escape certain characters in the content that might break sed
escaped_script2_content=$(echo "$script2_content" | sed 's/[&/\]/\\&/g')

# Use sed to insert the content into index.html just before </body>
sed -i "s|<div id=\"root\"></div>|<script>\n$(echo $escaped_script2_content)\n</script>\n&|" index.html
fi

# Continue executing the CMD
exec "$@"

0 comments on commit be16c3c

Please sign in to comment.