用于自定义 Server-Side Rendering 入口返回 requestHandler
import {
renderString,
createRequestHandler,
} from '@modern-js/runtime/ssr/server';
const handleRequest = async (request, ServerRoot, options) => {
const body = await renderString(request, <ServerRoot />, options);
return new Response(body, {
headers: {
'content-type': 'text/html; charset=utf-8',
},
});
};
export default createRequestHandler(handleRequest);
export type HandleRequest = (
request: Request,
ServerRoot: React.ComponentType
options: HandleRequestOptions,
) => Promise<Response>;
export type RequestHandler = (
request: Request,
options: RequestHandlerOptions,
) => Promise<Response>;
export type CreateRequestHandler = (
handleRequest: HandleRequest,
) => Promise<RequestHandler>;