Merge pull request #2195 from alexbelgium/codex/fix-issue-2126-in-hassio-addons

Fix ingress configuration for Calibre Selkies UI
This commit is contained in:
Alexandre
2025-11-15 11:18:40 +01:00
committed by GitHub
2 changed files with 15 additions and 17 deletions

View File

@@ -1,4 +1,3 @@
## ⚠ Open Issue : [🐛 [Calibre] Waiting for stream... / WebSocket disconnected. Attempting to reconnect... / Connection established. Waiting for server mode... (opened 2025-09-25)](https://github.com/alexbelgium/hassio-addons/issues/2126) by [@codyc1515](https://github.com/codyc1515)
# Home assistant add-on: calibre
[![Donate][donation-badge]](https://www.buymeacoffee.com/alexbelgium)

View File

@@ -2,34 +2,33 @@
# shellcheck shell=bash
set -e
# nginx Path
NGINX_CONFIG=/etc/nginx/sites-available/ingress.conf
SUBFOLDER="$(bashio::addon.ingress_entry)"
# Copy template
# Ensure subfolder ends with a trailing slash (except for root)
if [[ -n "${SUBFOLDER}" && "${SUBFOLDER}" != "/" ]]; then
[[ "${SUBFOLDER}" == */ ]] || SUBFOLDER="${SUBFOLDER}/"
else
SUBFOLDER="/"
fi
cp /defaults/default.conf "${NGINX_CONFIG}"
# Keep only the first (non-SSL) server block
awk -v n=2 '/^[[:space:]]*server[[:space:]]*\{/{n--} n>0' "${NGINX_CONFIG}" > tmpfile
mv tmpfile "${NGINX_CONFIG}"
# Remove ipv6
# Disable IPv6 listeners for ingress proxying
sed -i '/listen \[::\]/d' "${NGINX_CONFIG}"
# Add ingress parameters
# Adapt ports and upstream paths for Home Assistant ingress
sed -i "s|3000|$(bashio::addon.ingress_port)|g" "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a proxy_set_header Accept-Encoding "";' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter_once off;' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter_types *;' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter "vnc/index.html?autoconnect" "vnc/index.html?path=%%path%%/websockify?autoconnect";' "${NGINX_CONFIG}"
sed -i "s|%%path%%|${SUBFOLDER:1}|g" "${NGINX_CONFIG}"
# Replace placeholders
sed -i "s|SUBFOLDER|${SUBFOLDER}|g" "${NGINX_CONFIG}"
sed -i "s|CWS|8082|g" "${NGINX_CONFIG}"
sed -i "s|REPLACE_HOME|${HOME:-/root}|g" "${NGINX_CONFIG}"
sed -i "s|REPLACE_DOWNLOADS_PATH|${HOME:-/config}|g" "${NGINX_CONFIG}"
# Correct image
sed -i "s|SUBFOLDER|/|g" "${NGINX_CONFIG}"
# Avoid content encoding on proxied responses to keep Selkies happy
sed -i '/proxy_buffering/a \
proxy_set_header Accept-Encoding "";' "${NGINX_CONFIG}"
# Enable ingress
cp /etc/nginx/sites-available/ingress.conf /etc/nginx/sites-enabled
cp "${NGINX_CONFIG}" /etc/nginx/sites-enabled