Make live update badge injection robust

This commit is contained in:
Admin 2026-09-17 08:37:47 +00:00
parent c3f32acdd8
commit 51435b9307

View File

@ -3,8 +3,7 @@ import http from 'node:http';
const originalEnd = http.ServerResponse.prototype.end; const originalEnd = http.ServerResponse.prototype.end;
http.ServerResponse.prototype.end = function (chunk, encoding, callback) { http.ServerResponse.prototype.end = function (chunk, encoding, callback) {
const type = String(this.getHeader('content-type') || ''); if (typeof chunk === 'string' && chunk.includes('</body>')) {
if (typeof chunk === 'string' && type.startsWith('text/html') && chunk.includes('</body>')) {
const badge = '<div style="position:fixed;right:16px;bottom:16px;background:#1f6feb;color:#fff;padding:8px 12px;border-radius:999px;font:600 12px system-ui;box-shadow:0 8px 24px #0006">v2 · live update</div>'; const badge = '<div style="position:fixed;right:16px;bottom:16px;background:#1f6feb;color:#fff;padding:8px 12px;border-radius:999px;font:600 12px system-ui;box-shadow:0 8px 24px #0006">v2 · live update</div>';
chunk = chunk.replace('</body>', `${badge}</body>`); chunk = chunk.replace('</body>', `${badge}</body>`);
} }