-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from takeokunn/use-ssr
サイトに SSR を利用する
- Loading branch information
Showing
14 changed files
with
236 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* 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 type { AppLoadContext, 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( | ||
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! | ||
loadContext: AppLoadContext, | ||
) { | ||
const body = await renderToReadableStream( | ||
<RemixServer context={remixContext} url={request.url} />, | ||
{ | ||
signal: request.signal, | ||
onError(error: unknown) { | ||
// Log streaming rendering errors from inside the shell | ||
console.error(error); | ||
// biome-ignore lint/style/noParameterAssign: 自動生成されたコードのため | ||
responseStatusCode = 500; | ||
}, | ||
}, | ||
); | ||
|
||
if (isbot(request.headers.get("user-agent") || "")) { | ||
await body.allReady; | ||
} | ||
|
||
responseHeaders.set("Content-Type", "text/html"); | ||
return new Response(body, { | ||
headers: responseHeaders, | ||
status: responseStatusCode, | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { LoaderFunction } from "@remix-run/node"; | ||
|
||
export const indexLoader = (async () => { | ||
const res = await fetch("https://api.yasunori.dev/awesome"); | ||
if (res.ok) { | ||
const json = | ||
await res.json< | ||
{ | ||
id: number; | ||
title: string; | ||
content: string; | ||
date: string; | ||
at: string; | ||
senpan: string; | ||
meta: string; | ||
}[] | ||
>(); | ||
|
||
return json; | ||
} | ||
return null; | ||
}) satisfies LoaderFunction; | ||
|
||
export type IndexLoader = typeof indexLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore - the server build file is generated by `remix vite:build` | ||
// eslint-disable-next-line import/no-unresolved | ||
import * as build from "../build/server"; | ||
|
||
export const onRequest = createPagesFunctionHandler({ build }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { PlatformProxy } from "wrangler"; | ||
|
||
// When using `wrangler.toml` to configure bindings, | ||
// `wrangler types` will generate types for those bindings | ||
// into the global `Env` interface. | ||
// Need this empty interface so that typechecking passes | ||
// even if no `wrangler.toml` exists. | ||
// biome-ignore lint/suspicious/noEmptyInterface: <explanation> | ||
interface Env {} | ||
|
||
type Cloudflare = Omit<PlatformProxy<Env>, "dispose">; | ||
|
||
declare module "@remix-run/cloudflare" { | ||
interface AppLoadContext { | ||
cloudflare: Cloudflare; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.