minisrv_service_file = true; request_is_async = true; proxyUrl = minisrv_config.services[service_name].wrp_url; if (!proxyUrl) { headers = `200 OK Content-Type: text/html wtv-expire-all: wtv-proxy:/`; data = ` Web Rendering Proxy

Web Rendering Proxy

Sorry, the Web Rendering Proxy is not enabled on this service.
`; sendToClient(socket, headers, data); } else { if (!proxyUrl.endsWith('/')) { proxyUrl += '/'; } if (!request_headers.query.url) { headers = `200 OK Content-Type: text/html wtv-expire-all: wtv-proxy:/`; data = ` Web Rendering Proxy

Web Rendering Proxy

Welcome to the Web Rendering Proxy.
Please provide a valid URL to render.


Back to Tricks
` sendToClient(socket, headers, data); } else { if (request_headers.query.err) { finishPage(`

Error

${request_headers.query.err}

`); } else { if (request_headers.query.Fn) { if (typeof request_headers.query.Fn !== 'string') { request_headers.query.Fn = request_headers.query.Fn[0]; } } const params = new URLSearchParams({ url: request_headers.query.url, z: request_headers.query.z || '1.0', t: request_headers.query.t || 'jpg', c: request_headers.query.c || '256', h: request_headers.query.h || '426', w: request_headers.query.w || '640', m: request_headers.query.m || 'ismap', Fn: request_headers.query.Fn || '' }); if (params.get('Fn') === '129') { params.set('Fn', 'Bk'); } if (params.get('Fn') === 'Home') { headers = `302 Moved Location: wtv-proxy:/proxy` data = ''; sendToClient(socket, headers, data); } else { const urlObj = new URL(proxyUrl); const post_data = params.toString(); const options = { protocol: urlObj.protocol, hostname: urlObj.hostname, port: parseInt(urlObj.port), path: urlObj.pathname, method: 'POST', headers: { 'User-Agent': request_headers['User-Agent'] || 'Mozilla/4.0 WebTV/2.6 (compatible; MSIE 4.0)', 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(post_data) } } const lib = urlObj.protocol === 'https:' ? https : http; if (request_headers.query.id) { finishPage(``); } else { function fetch(options, post_data) { return new Promise((resolve, reject) => { req = lib.request(options, (res) => { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => resolve({ text: () => Promise.resolve(data) })); }).on('error', reject); req.write(post_data); // 🔁 Send body req.end(); }); } fetch(options, post_data) .then(response => response.text()) .then(text => { process(text); }) .catch(err => { finishPage(`Error fetching page: ${err.message}`); }); } } } } } function process(content) { if (content.startsWith(' and extract the URLs const aHrefMatch = content.match(/]+type=["']text["'][^>]+name=["']url["'][^>]+value=["']([^"']+)["']/i); let pageUrl = request_headers.query.url || ''; if (urlInputMatch) { pageUrl = urlInputMatch[1]; } finishPage(links.map(link => ``).join('
'), pageUrl); // You can now use the `links` array as needed } else { var idx = content.indexOf('
'); content = content.substring(0, idx); finishPage(content); } } function finishPage(content, url = null) { headers = `200 OK Content-Type: text/html wtv-expire-all: wtv-proxy:/`; data = ` Web Rendering Proxy

${content}
`; sendToClient(socket, headers, data); }