From 938f0a0f7ba9e883fc838f266f46aac5f6664059 Mon Sep 17 00:00:00 2001 From: Thomas Fritz Date: Thu, 6 Jun 2024 18:04:57 +0200 Subject: [PATCH] Some modifications --- .github/workflows/fly.yaml | 1 + app/entry.client.tsx | 18 ----- app/entry.server.tsx | 140 ------------------------------------- app/routes/_index.tsx | 17 ++--- 4 files changed, 5 insertions(+), 171 deletions(-) delete mode 100644 app/entry.client.tsx delete mode 100644 app/entry.server.tsx diff --git a/.github/workflows/fly.yaml b/.github/workflows/fly.yaml index 8f66931..ac250d0 100644 --- a/.github/workflows/fly.yaml +++ b/.github/workflows/fly.yaml @@ -21,6 +21,7 @@ jobs: environment: name: production + url: https://f42demo-my-remix-app.fly.dev/ steps: - uses: actions/checkout@v4 diff --git a/app/entry.client.tsx b/app/entry.client.tsx deleted file mode 100644 index 94d5dc0..0000000 --- a/app/entry.client.tsx +++ /dev/null @@ -1,18 +0,0 @@ -/** - * By default, Remix will handle hydrating your app on the client for you. - * You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨ - * For more information, see https://remix.run/file-conventions/entry.client - */ - -import { RemixBrowser } from "@remix-run/react"; -import { startTransition, StrictMode } from "react"; -import { hydrateRoot } from "react-dom/client"; - -startTransition(() => { - hydrateRoot( - document, - - - - ); -}); diff --git a/app/entry.server.tsx b/app/entry.server.tsx deleted file mode 100644 index 45db322..0000000 --- a/app/entry.server.tsx +++ /dev/null @@ -1,140 +0,0 @@ -/** - * By default, Remix will handle generating the HTTP Response for you. - * You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨ - * For more information, see https://remix.run/file-conventions/entry.server - */ - -import { PassThrough } from "node:stream"; - -import type { AppLoadContext, 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"; - -const ABORT_DELAY = 5_000; - -export default function handleRequest( - request: Request, - responseStatusCode: number, - responseHeaders: Headers, - remixContext: EntryContext, - // This is ignored so we can keep it in the template for visibility. Feel - // free to delete this parameter in your app if you're not using it! - // eslint-disable-next-line @typescript-eslint/no-unused-vars - loadContext: AppLoadContext -) { - 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( - , - { - 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; - // Log streaming rendering errors from inside the shell. Don't log - // errors encountered during initial shell rendering since they'll - // reject and get logged in handleDocumentRequest. - if (shellRendered) { - console.error(error); - } - }, - } - ); - - setTimeout(abort, ABORT_DELAY); - }); -} - -function handleBrowserRequest( - request: Request, - responseStatusCode: number, - responseHeaders: Headers, - remixContext: EntryContext -) { - return new Promise((resolve, reject) => { - let shellRendered = false; - const { pipe, abort } = renderToPipeableStream( - , - { - 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; - // Log streaming rendering errors from inside the shell. Don't log - // errors encountered during initial shell rendering since they'll - // reject and get logged in handleDocumentRequest. - if (shellRendered) { - console.error(error); - } - }, - } - ); - - setTimeout(abort, ABORT_DELAY); - }); -} diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 5347369..5297845 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -2,7 +2,7 @@ import type { MetaFunction } from "@remix-run/node"; export const meta: MetaFunction = () => { return [ - { title: "New Remix App" }, + { title: "New Remix App on Fly.io" }, { name: "description", content: "Welcome to Remix!" }, ]; }; @@ -10,24 +10,15 @@ export const meta: MetaFunction = () => { export default function Index() { return (
-

Welcome to Remix

+

Welcome to Remix on Fly.io