Skip to content

Commit

Permalink
chore: update cloudflare/deno default entry.server
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh committed Jan 23, 2023
1 parent 967a649 commit 6e4df31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
22 changes: 12 additions & 10 deletions packages/remix-dev/config/defaults/entry.server.cloudflare.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EntryContext } from "@remix-run/cloudflare";
import { type EntryContext } from "@remix-run/cloudflare";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToReadableStream } from "react-dom/server";

export default async function handleRequest(
Expand All @@ -8,23 +9,24 @@ export default async function handleRequest(
responseHeaders: Headers,
remixContext: EntryContext
) {
let didError = false;

const stream = await renderToReadableStream(
const body = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
signal: request.signal,
onError(error: unknown) {
didError = true;
onError(error) {
console.error("renderToReadableStream error");
console.error(error);
responseStatusCode = 500;
},
}
);

responseHeaders.set("Content-Type", "text/html");
if (isbot(request.headers.get("user-agent"))) {
await body.allReady;
}

return new Response(stream, {
responseHeaders.set("Content-Type", "text/html");
return new Response(body, {
headers: responseHeaders,
status: didError ? 500 : responseStatusCode,
status: responseStatusCode,
});
}
22 changes: 12 additions & 10 deletions packages/remix-dev/config/defaults/entry.server.deno.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EntryContext } from "@remix-run/deno";
import { type EntryContext } from "@remix-run/cloudflare";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToReadableStream } from "react-dom/server";

export default async function handleRequest(
Expand All @@ -8,23 +9,24 @@ export default async function handleRequest(
responseHeaders: Headers,
remixContext: EntryContext
) {
let didError = false;

const stream = await renderToReadableStream(
const body = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
signal: request.signal,
onError(error: unknown) {
didError = true;
onError(error) {
console.error("renderToReadableStream error");
console.error(error);
responseStatusCode = 500;
},
}
);

responseHeaders.set("Content-Type", "text/html");
if (isbot(request.headers.get("user-agent"))) {
await body.allReady;
}

return new Response(stream, {
responseHeaders.set("Content-Type", "text/html");
return new Response(body, {
headers: responseHeaders,
status: didError ? 500 : responseStatusCode,
status: responseStatusCode,
});
}

0 comments on commit 6e4df31

Please sign in to comment.