import {
renderStreaming,
createRequestHandler,
} from '@modern-js/runtime/ssr/server';
const handleRequest = async (request, ServerRoot, options) => {
// do something before render
const stream = await renderStreaming(request, <ServerRoot />, options);
// docs: https://developer.mozilla.org/en-US/docs/Web/API/TransformStream
const transformStream = new TransformStream({
transform(chunk, controller) {
// do some transform
},
});
stream.pipeThrough(transformStream);
return new Response(transformStream.readable, {
headers: {
'content-type': 'text/html; charset=utf-8',
},
});
};
export default createRequestHandler(handleRequest);