import { DOMParser } from 'linkedom'; import { renderPage, siteFromCommon } from '../.ssr/entry-server.js'; import { createDocument } from './seo-document.mjs'; // A single public JSON request on stdin. No DB credentials, cookies or browser // session are required. Go controls input and enforces timeout/concurrency. globalThis.DOMParser = DOMParser; // Декодер потока собирает UTF-8 целиком: при склейке сырых кусков (по 64 КБ) русская буква // на границе куска превращалась в «��» прямо в тексте страницы. process.stdin.setEncoding('utf8'); let input = ''; let bytes = 0; for await (const chunk of process.stdin) { input += chunk; bytes += Buffer.byteLength(chunk); if (bytes > 16 * 1024 * 1024) throw new Error('Render input exceeds 16 MB'); } const request = JSON.parse(input); const data = { ...request.initial, site: siteFromCommon(request.common) }; const result = renderPage(request.url, data, request.siteURL); process.stdout.write(createDocument(request.template, result));