feat(clickTtHttpPageRoutes): add base tag handling for relative URLs in proxy response

- Implemented logic to dynamically insert a base tag in the HTML response for relative URLs, ensuring proper resolution of form actions during login.
- Enhanced the existing proxy route to improve handling of HTML content fetched from target URLs.
This commit is contained in:
Torsten Schulz (local)
2026-03-10 22:01:39 +01:00
parent a3148a3781
commit c87cebba36

View File

@@ -104,6 +104,13 @@ router.get('/proxy', async (req, res, next) => {
.replace(/<meta[^>]*http-equiv=["']x-frame-options["'][^>]*>/gi, '')
.replace(/<meta[^>]*http-equiv=["']x-content-type-options["'][^>]*>/gi, '');
// Base-Tag: Relative URLs (z.B. Formular-Actions beim Login) müssen zur Original-Domain auflösen
const pageOrigin = (() => { try { return new URL(targetUrl).origin + '/'; } catch { return null; } })();
if (pageOrigin) {
html = html.replace(/<base[^>]*>/gi, '');
html = html.replace(/<head([^>]*)>/i, `<head$1><base href="${pageOrigin}">`);
}
// Links umschreiben: Klicks im iframe laufen über unseren Proxy → Folge-Logs
// URL aus .env (BACKEND_BASE_URL oder BASE_URL), Fallback: Request-Host
const baseUrl = process.env.BACKEND_BASE_URL || process.env.BASE_URL