Skip to content

Commit 722a547

Browse files
committed
update readme
1 parent 672b5a7 commit 722a547

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# hono-remix-adapter
22

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.
44

55
```ts
66
// server/index.ts
@@ -120,6 +120,42 @@ import server from '../server'
120120
export const onRequest = handle(build, server)
121121
```
122122

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+
123159
## `getLoadContext`
124160

125161
If you want to add extra context values when you use Remix routes, like in the following use case:

examples/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
"engines": {
3838
"node": ">=20.0.0"
3939
}
40-
}
40+
}

0 commit comments

Comments
 (0)