UNPKG

lit-ssr-utils

Version:

Lit utils to implement SSR to projects that do not use Javascript.

2 lines (1 loc) 624 B
import x from"fs/promises";import*as z from"protobufjs";import I from"../../rpc";var i="/tmp/lit-ssr.sock";async function J(){if(await x.exists(i))await x.unlink(i);const g=await z.load(import.meta.dir+"../../../proto/ssr.proto"),l=g.lookupType("Request"),n=g.lookupType("Response"),A=Bun.serve({unix:i,async fetch(B){try{const w=Buffer.from(await B.arrayBuffer()),C=l.decode(w),E=l.toObject(C),F=await I(E),G=n.create(F),H=n.encode(G).finish(),v=new Response(H);return v.headers.set("Content-Type","application/protobuf"),v}catch(w){throw w}}});console.log(`Server listening on unix://${i}!`),await A}export{J as default};