|
1 | 1 | # hono-remix-adapter |
2 | 2 |
|
3 | | -`hono-remix-adapter` is a set of tools for adapting between Hono and Remix. It is composed of a Vite plugin and handlers that enable it to support platforms like Cloudflare Workers. You can create an Hono app, and it will be applied to your Remix app. |
| 3 | +`hono-remix-adapter` is a set of tools for adapting between Hono and Remix. It is composed of a Vite plugin and handlers that enable it to support platforms like Cloudflare Workers and Node.js. You just create Hono app, and it will be applied to your Remix app. |
4 | 4 |
|
5 | 5 | ```ts |
6 | 6 | // server/index.ts |
@@ -120,6 +120,42 @@ import server from '../server' |
120 | 120 | export const onRequest = handle(build, server) |
121 | 121 | ``` |
122 | 122 |
|
| 123 | +## Node.js |
| 124 | + |
| 125 | +If you want to run your app on Node.js, you can use `hono-remix-adapter/node`. Write `main.ts`: |
| 126 | + |
| 127 | +```ts |
| 128 | +// main.ts |
| 129 | +import { serve } from '@hono/node-server' |
| 130 | +import { serveStatic } from '@hono/node-server/serve-static' |
| 131 | +import handle from 'hono-remix-adapter/node' |
| 132 | +import * as build from './build/server' |
| 133 | +import { getLoadContext } from './load-context' |
| 134 | +import server from './server' |
| 135 | + |
| 136 | +server.use( |
| 137 | + serveStatic({ |
| 138 | + root: './build/client', |
| 139 | + }) |
| 140 | +) |
| 141 | + |
| 142 | +const handler = handle(build, server, { getLoadContext }) |
| 143 | + |
| 144 | +serve({ fetch: handler.fetch, port: 3010 }) |
| 145 | +``` |
| 146 | + |
| 147 | +Run `main.ts` with [`tsx`](https://github.com/privatenumber/tsx): |
| 148 | + |
| 149 | +```bash |
| 150 | +tsx main.ts |
| 151 | +``` |
| 152 | + |
| 153 | +Or you can compile to a pure JavaScript file with `esbuild` with the command below: |
| 154 | + |
| 155 | +```bash |
| 156 | +esbuild main.ts --bundle --outfile=main.mjs --platform=node --target=node16.8 --format=esm --banner:js='import { createRequire as topLevelCreateRequire } from "module"; const require = topLevelCreateRequire(import.meta.url);' |
| 157 | +``` |
| 158 | + |
123 | 159 | ## `getLoadContext` |
124 | 160 |
|
125 | 161 | If you want to add extra context values when you use Remix routes, like in the following use case: |
|
0 commit comments