---
title: createRequestHandler
---

# createRequestHandler

Used to customize the Server-Side Rendering entry to return the `requestHandler`.

## Usage

```tsx title="src/entry.server.tsx"
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);
```

## Function Signature

```ts
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>;
```
