You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/framework-conventions/entry.server.tsx.md
+12-10Lines changed: 12 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,17 +9,18 @@ order: 5
9
9
10
10
## Summary
11
11
12
-
<docs-info>
13
-
This file is optional
14
-
</docs-info>
15
-
16
12
This file is the server-side entry point that controls how your React Router application generates HTTP responses on the server.
17
13
18
14
This module should render the markup for the current page using a [`<ServerRouter>`][serverrouter] element with the `context` and `url` for the current request. This markup will (optionally) be re-hydrated once JavaScript loads in the browser using the [client entry module][client-entry].
19
15
16
+
<docs-info>This file is optional if you are running on Node. If it is not present, a [default implementation][node-streaming-entry-server] will be used.
17
+
<br/>
18
+
<br/>
19
+
If you are using another runtime (i.e., Cloudflare) then you need to include this file. You can find sample implementations in the [templates repository][templates-repo].</docs-info>
20
+
20
21
## Generating `entry.server.tsx`
21
22
22
-
By default, React Router will handle generating the HTTP Response for you. You can reveal the default entry server file with the following:
23
+
When running in Node, React Router will handle generating the HTTP Response for you. You can reveal the default entry server file with the following:
23
24
24
25
```shellscript nonumber
25
26
npx react-router reveal
@@ -42,7 +43,7 @@ export default function handleRequest(
42
43
request:Request,
43
44
responseStatusCode:number,
44
45
responseHeaders:Headers,
45
-
routerContext:EntryContext
46
+
routerContext:EntryContext,
46
47
) {
47
48
returnnewPromise((resolve, reject) => {
48
49
const { pipe, abort } =renderToPipeableStream(
@@ -62,15 +63,15 @@ export default function handleRequest(
62
63
newResponse(stream, {
63
64
headers: responseHeaders,
64
65
status: responseStatusCode,
65
-
})
66
+
}),
66
67
);
67
68
68
69
pipe(body);
69
70
},
70
71
onShellError(error:unknown) {
71
72
reject(error);
72
73
},
73
-
}
74
+
},
74
75
);
75
76
});
76
77
}
@@ -113,7 +114,7 @@ export function handleDataRequest(
113
114
request,
114
115
params,
115
116
context,
116
-
}:LoaderFunctionArgs|ActionFunctionArgs
117
+
}:LoaderFunctionArgs|ActionFunctionArgs,
117
118
) {
118
119
response.headers.set("X-Custom-Header", "value");
119
120
returnresponse;
@@ -131,7 +132,7 @@ export function handleError(
131
132
request,
132
133
params,
133
134
context,
134
-
}:LoaderFunctionArgs|ActionFunctionArgs
135
+
}:LoaderFunctionArgs|ActionFunctionArgs,
135
136
) {
136
137
if (!request.signal.aborted) {
137
138
sendErrorToErrorReportingService(error);
@@ -160,3 +161,4 @@ Note that this does not handle thrown `Response` instances from your `loader`/`a
0 commit comments