Highly ambitious ATProtocol AppView service and sdks
at main 30 lines 728 B view raw
1import { render } from "preact-render-to-string"; 2import { VNode } from "preact"; 3 4/** 5 * Renders JSX to an HTML Response with proper headers 6 * @param jsx - The JSX element to render 7 * @param options - Optional response configuration 8 * @returns A Response object with rendered HTML 9 */ 10export function renderHTML( 11 jsx: VNode, 12 options?: { 13 status?: number; 14 headers?: Record<string, string>; 15 title?: string; 16 description?: string; 17 }, 18): Response { 19 const html = render(jsx); 20 21 const headers: Record<string, string> = { 22 "content-type": "text/html; charset=utf-8", 23 ...options?.headers, 24 }; 25 26 return new Response(`<!DOCTYPE html>${html}`, { 27 status: options?.status || 200, 28 headers, 29 }); 30}