From a3148a37817842cc23a4f8e7962ad6b1a64352d3 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Tue, 10 Mar 2026 21:57:43 +0100 Subject: [PATCH] feat(readme): add configuration details for link rewriting and update proxy URL handling - Introduced a new section in the README for environment variable configuration related to link rewriting, specifying BACKEND_BASE_URL and BASE_URL usage. - Updated the clickTtHttpPageRoutes to dynamically construct the proxy base URL from environment variables, enhancing flexibility for different deployment environments. --- backend/CLICKTT_HTTV_README.md | 9 +++++++++ backend/routes/clickTtHttpPageRoutes.js | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/CLICKTT_HTTV_README.md b/backend/CLICKTT_HTTV_README.md index 3948d280..00d64bdc 100644 --- a/backend/CLICKTT_HTTV_README.md +++ b/backend/CLICKTT_HTTV_README.md @@ -96,6 +96,15 @@ GET /api/clicktt/logs?limit=50&fetchType=leaguePage&association=HeTTV GET /api/clicktt/url-info ``` +## Konfiguration (.env) + +Für das Link-Rewriting (Folge-Klicks im iframe) wird die Backend-URL benötigt: + +- **BACKEND_BASE_URL** – URL, unter der die API erreichbar ist (z.B. `https://tt-tagebuch.de`) +- **BASE_URL** – Fallback, falls BACKEND_BASE_URL nicht gesetzt ist + +In Produktion mit Reverse-Proxy (Apache) reicht meist `BASE_URL=https://tt-tagebuch.de`. In der Entwicklung kann `BACKEND_BASE_URL=http://localhost:3005` nötig sein, wenn die API auf einem anderen Port als das Frontend läuft. + ## Datenbank-Migration ```bash diff --git a/backend/routes/clickTtHttpPageRoutes.js b/backend/routes/clickTtHttpPageRoutes.js index 2f686a89..f195ba57 100644 --- a/backend/routes/clickTtHttpPageRoutes.js +++ b/backend/routes/clickTtHttpPageRoutes.js @@ -105,9 +105,10 @@ router.get('/proxy', async (req, res, next) => { .replace(/]*http-equiv=["']x-content-type-options["'][^>]*>/gi, ''); // Links umschreiben: Klicks im iframe laufen über unseren Proxy → Folge-Logs - const protocol = req.protocol || 'http'; - const host = req.get('host') || 'localhost:3005'; - const proxyBase = `${protocol}://${host}/api/clicktt/proxy`; + // URL aus .env (BACKEND_BASE_URL oder BASE_URL), Fallback: Request-Host + const baseUrl = process.env.BACKEND_BASE_URL || process.env.BASE_URL + || `${req.protocol || 'http'}://${req.get('host') || 'localhost:' + (process.env.PORT || 3005)}`; + const proxyBase = baseUrl.replace(/\/$/, '') + '/api/clicktt/proxy'; html = rewriteLinksInHtml(html, proxyBase, targetUrl); res.set({