Add post-video redirect to YouTube URL from env config.

After the intro finishes, users are redirected to POST_VIDEO_REDIRECT_URL loaded via generated config.js for dev, Docker, and Dokploy deployments.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-26 15:36:38 +02:00
parent d17987efed
commit 833e248518
10 changed files with 70 additions and 3 deletions
+4
View File
@@ -6,3 +6,7 @@
# Port na hoście (localhost). W kontenerze nginx zawsze nasłuchuje na 80. # Port na hoście (localhost). W kontenerze nginx zawsze nasłuchuje na 80.
# Mapowanie w docker-compose.yml: ${FRONTEND_PORT}:80 # Mapowanie w docker-compose.yml: ${FRONTEND_PORT}:80
FRONTEND_PORT=8082 FRONTEND_PORT=8082
# --- Po zakończeniu intro wideo ---
# Adres docelowy przekierowania po zakończeniu odtwarzania filmu.
POST_VIDEO_REDIRECT_URL=https://www.youtube.com/watch?v=kujXXtoHUbc
+3
View File
@@ -2,6 +2,9 @@
.env .env
*.env.local *.env.local
# Generated from .env at dev/build time
config.js
# Python # Python
__pycache__/ __pycache__/
.venv/ .venv/
+4 -2
View File
@@ -11,9 +11,11 @@ COPY index.html /usr/share/nginx/html/index.html
COPY site.webmanifest /usr/share/nginx/html/site.webmanifest COPY site.webmanifest /usr/share/nginx/html/site.webmanifest
COPY assets/ /usr/share/nginx/html/assets/ COPY assets/ /usr/share/nginx/html/assets/
# Generate config.js from env vars at container start
COPY generate-config.sh /docker-entrypoint.d/99-generate-config.sh
RUN chmod +x /docker-entrypoint.d/99-generate-config.sh
EXPOSE 80 EXPOSE 80
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget -qO- http://localhost:80/ || exit 1 CMD wget -qO- http://localhost:80/ || exit 1
CMD ["nginx", "-g", "daemon off;"]
+16 -1
View File
@@ -10,8 +10,18 @@ if [[ ! -f .env ]]; then
echo "Utworzono .env z .env.example" echo "Utworzono .env z .env.example"
fi fi
generate_config() {
set -a
# shellcheck disable=SC1091
source .env
set +a
./generate-config.sh config.js
}
case "${1:-up}" in case "${1:-up}" in
up) up)
chmod +x generate-config.sh
generate_config
$COMPOSE up -d $COMPOSE up -d
echo "" echo ""
echo "Dev server: http://localhost:${FRONTEND_PORT:-8082}" echo "Dev server: http://localhost:${FRONTEND_PORT:-8082}"
@@ -24,14 +34,19 @@ case "${1:-up}" in
$COMPOSE logs -f $COMPOSE logs -f
;; ;;
restart) restart)
generate_config
$COMPOSE restart $COMPOSE restart
;; ;;
config)
generate_config
echo "Wygenerowano config.js (POST_VIDEO_REDIRECT_URL z .env)."
;;
reload-nginx) reload-nginx)
docker exec slavic-pulse-com-frontend nginx -s reload docker exec slavic-pulse-com-frontend nginx -s reload
echo "Nginx przeładowany (po zmianie default.conf)." echo "Nginx przeładowany (po zmianie default.conf)."
;; ;;
*) *)
echo "Użycie: $0 [up|down|logs|restart|reload-nginx]" echo "Użycie: $0 [up|down|logs|restart|reload-nginx|config]"
exit 1 exit 1
;; ;;
esac esac
+4
View File
@@ -7,3 +7,7 @@
# Mapowanie w docker-compose.yml: ${FRONTEND_PORT}:80 # Mapowanie w docker-compose.yml: ${FRONTEND_PORT}:80
# Dokploy/Traefik dodatkowo routuje po FQDN do wewnętrznego portu 80 kontenera. # Dokploy/Traefik dodatkowo routuje po FQDN do wewnętrznego portu 80 kontenera.
FRONTEND_PORT=8082 FRONTEND_PORT=8082
# --- Po zakończeniu intro wideo ---
# Adres docelowy przekierowania po zakończeniu odtwarzania filmu.
POST_VIDEO_REDIRECT_URL=https://www.youtube.com/watch?v=kujXXtoHUbc
@@ -18,6 +18,9 @@ services:
ports: ports:
- "${FRONTEND_PORT:-8080}:80" - "${FRONTEND_PORT:-8080}:80"
environment:
POST_VIDEO_REDIRECT_URL: ${POST_VIDEO_REDIRECT_URL:-https://www.youtube.com/watch?v=kujXXtoHUbc}
command: > command: >
sh -c " sh -c "
apk add --no-cache git && apk add --no-cache git &&
@@ -28,6 +31,8 @@ services:
cp -r /app/assets /usr/share/nginx/html/assets && cp -r /app/assets /usr/share/nginx/html/assets &&
rm /etc/nginx/conf.d/default.conf && rm /etc/nginx/conf.d/default.conf &&
cp /app/default.conf /etc/nginx/conf.d/default.conf && cp /app/default.conf /etc/nginx/conf.d/default.conf &&
chmod +x /app/generate-config.sh &&
POST_VIDEO_REDIRECT_URL=\"$${POST_VIDEO_REDIRECT_URL}\" /app/generate-config.sh /usr/share/nginx/html/config.js &&
nginx -g 'daemon off;' nginx -g 'daemon off;'
" "
+5
View File
@@ -5,8 +5,13 @@ services:
frontend: frontend:
image: nginx:1.27-alpine image: nginx:1.27-alpine
build: !reset null build: !reset null
env_file:
- .env
environment:
POST_VIDEO_REDIRECT_URL: ${POST_VIDEO_REDIRECT_URL:-https://www.youtube.com/watch?v=kujXXtoHUbc}
volumes: volumes:
- ./index.html:/usr/share/nginx/html/index.html:ro - ./index.html:/usr/share/nginx/html/index.html:ro
- ./config.js:/usr/share/nginx/html/config.js:ro
- ./site.webmanifest:/usr/share/nginx/html/site.webmanifest:ro - ./site.webmanifest:/usr/share/nginx/html/site.webmanifest:ro
- ./assets:/usr/share/nginx/html/assets:ro - ./assets:/usr/share/nginx/html/assets:ro
- ./default.conf:/etc/nginx/conf.d/default.conf:ro - ./default.conf:/etc/nginx/conf.d/default.conf:ro
+4
View File
@@ -8,5 +8,9 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: slavic-pulse-com-frontend container_name: slavic-pulse-com-frontend
restart: unless-stopped restart: unless-stopped
env_file:
- .env
environment:
POST_VIDEO_REDIRECT_URL: ${POST_VIDEO_REDIRECT_URL:-https://www.youtube.com/watch?v=kujXXtoHUbc}
ports: ports:
- "${FRONTEND_PORT:-8080}:80" - "${FRONTEND_PORT:-8080}:80"
+19
View File
@@ -0,0 +1,19 @@
#!/bin/sh
# Generuje config.js z zmiennych środowiskowych (np. z pliku .env).
set -eu
if [ -n "${1:-}" ]; then
OUTPUT="$1"
elif [ -d /usr/share/nginx/html ]; then
OUTPUT="/usr/share/nginx/html/config.js"
else
OUTPUT="config.js"
fi
POST_VIDEO_REDIRECT_URL="${POST_VIDEO_REDIRECT_URL:-https://www.youtube.com/watch?v=kujXXtoHUbc}"
cat > "$OUTPUT" <<EOF
window.SLAVIC_PULSE_CONFIG = {
postVideoRedirectUrl: '${POST_VIDEO_REDIRECT_URL}'
};
EOF
+6
View File
@@ -154,8 +154,11 @@
</div> </div>
</div> </div>
<script src="/config.js"></script>
<script> <script>
const config = window.SLAVIC_PULSE_CONFIG || {};
const VIDEO_ID = 'kujXXtoHUbc'; const VIDEO_ID = 'kujXXtoHUbc';
const POST_VIDEO_REDIRECT_URL = config.postVideoRedirectUrl || '';
const BG_IMAGE = '/assets/imgs/www-bg-slavic-pulse-com-001.jpg'; const BG_IMAGE = '/assets/imgs/www-bg-slavic-pulse-com-001.jpg';
let player; let player;
@@ -239,6 +242,9 @@
function onPlayerStateChange(event) { function onPlayerStateChange(event) {
if (event.data === YT.PlayerState.ENDED) { if (event.data === YT.PlayerState.ENDED) {
stageVideo.classList.remove('active'); stageVideo.classList.remove('active');
if (POST_VIDEO_REDIRECT_URL) {
window.location.href = POST_VIDEO_REDIRECT_URL;
}
} }
} }