aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/entry.server.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/entry.server.tsx')
-rw-r--r--frontend/app/entry.server.tsx116
1 files changed, 0 insertions, 116 deletions
diff --git a/frontend/app/entry.server.tsx b/frontend/app/entry.server.tsx
deleted file mode 100644
index 6234421..0000000
--- a/frontend/app/entry.server.tsx
+++ /dev/null
@@ -1,116 +0,0 @@
-import { PassThrough } from "node:stream";
-
-import type { EntryContext } from "@remix-run/node";
-import { createReadableStreamFromReadable } from "@remix-run/node";
-import { RemixServer } from "@remix-run/react";
-import { isbot } from "isbot";
-import { renderToPipeableStream } from "react-dom/server";
-
-export const streamTimeout = 5000;
-
-export default function handleRequest(
- request: Request,
- responseStatusCode: number,
- responseHeaders: Headers,
- remixContext: EntryContext,
-) {
- return isbot(request.headers.get("user-agent") || "")
- ? handleBotRequest(
- request,
- responseStatusCode,
- responseHeaders,
- remixContext,
- )
- : handleBrowserRequest(
- request,
- responseStatusCode,
- responseHeaders,
- remixContext,
- );
-}
-
-function handleBotRequest(
- request: Request,
- responseStatusCode: number,
- responseHeaders: Headers,
- remixContext: EntryContext,
-) {
- return new Promise((resolve, reject) => {
- let shellRendered = false;
- const { pipe, abort } = renderToPipeableStream(
- <RemixServer context={remixContext} url={request.url} />,
- {
- onAllReady() {
- shellRendered = true;
- const body = new PassThrough();
- const stream = createReadableStreamFromReadable(body);
-
- responseHeaders.set("Content-Type", "text/html");
-
- resolve(
- new Response(stream, {
- headers: responseHeaders,
- status: responseStatusCode,
- }),
- );
-
- pipe(body);
- },
- onShellError(error: unknown) {
- reject(error);
- },
- onError(error: unknown) {
- responseStatusCode = 500;
- if (shellRendered) {
- console.error(error);
- }
- },
- },
- );
-
- +setTimeout(abort, streamTimeout + 1000);
- });
-}
-
-function handleBrowserRequest(
- request: Request,
- responseStatusCode: number,
- responseHeaders: Headers,
- remixContext: EntryContext,
-) {
- return new Promise((resolve, reject) => {
- let shellRendered = false;
- const { pipe, abort } = renderToPipeableStream(
- <RemixServer context={remixContext} url={request.url} />,
- {
- onShellReady() {
- shellRendered = true;
- const body = new PassThrough();
- const stream = createReadableStreamFromReadable(body);
-
- responseHeaders.set("Content-Type", "text/html");
-
- resolve(
- new Response(stream, {
- headers: responseHeaders,
- status: responseStatusCode,
- }),
- );
-
- pipe(body);
- },
- onShellError(error: unknown) {
- reject(error);
- },
- onError(error: unknown) {
- responseStatusCode = 500;
- if (shellRendered) {
- console.error(error);
- }
- },
- },
- );
-
- setTimeout(abort, streamTimeout + 1000);
- });
-}