1- # Remix + Hono
1+ # Remix/React Router + Hono
22
3- > [ Remix ] ( https://remix.run ) is a web framework for building web applications,
4- > which can run on the Edge.
3+ > [ React Router ] ( https://remix.run ) is a web framework for building web
4+ > applications, which can run on the Edge.
55
66> [ Hono] ( https://hono.dev ) is a small and ultrafast web framework for the Edges.
77
8- This adapter allows you to use Hono with Remix , so you can use the best of each
9- one.
8+ This adapter allows you to use Hono with React Router , so you can use the best
9+ of each one.
1010
11- Let Hono power your HTTP server and its middlewares, then use Remix to build
12- your web application.
11+ Let Hono power your HTTP server and its middlewares, then use React Router to
12+ build your web application.
1313
1414## Installation
1515
@@ -22,26 +22,26 @@ npm add remix-hono
2222The following packages are optional dependencies, you will need to install them
2323depending on what features from remix-hono you're using.
2424
25- - ` @remix-run /cloudflare ` if you're using Cloudflare integration.
25+ - ` @react-router /cloudflare ` if you're using Cloudflare integration.
2626- ` i18next ` and ` remix-i18next ` if you're using the i18n middleware.
2727- ` zod ` if you're using ` typedEnv ` .
2828
29- > [ !NOTE]
30- > You don't really need to install them if you don't use them, but you
29+ > [ !NOTE] You don't really need to install them if you don't use them, but you
3130> will need to install them yourself (they don't come not automatically) if you
3231> use the features that depends on those packages.
3332
3433## Usage
3534
36- Create your Hono + Remix server:
35+ Create your Hono + React Routers server:
3736
3837``` ts
39- import { logDevReady } from " @remix-run/cloudflare" ;
40- import * as build from " @remix-run/dev/server-build" ;
38+ import { logDevReady } from " @react-router/cloudflare" ;
4139import { Hono } from " hono" ;
4240// You can also use it with other runtimes
4341import { handle } from " hono/cloudflare-pages" ;
44- import { remix } from " remix-hono/handler" ;
42+ import { reactRouter } from " remix-hono/handler" ;
43+
44+ import build from " ./build/server" ;
4545
4646if (process .env .NODE_ENV === " development" ) logDevReady (build );
4747
@@ -55,10 +55,10 @@ type ContextEnv = { Bindings: Bindings; Variables: Variables };
5555
5656const server = new Hono <ContextEnv >();
5757
58- // Add the Remix middleware to your Hono server
58+ // Add the React Router middleware to your Hono server
5959server .use (
6060 " *" ,
61- remix ({
61+ reactRouter ({
6262 build ,
6363 mode: process .env .NODE_ENV as " development" | " production" ,
6464 // getLoadContext is optional, the default function is the same as here
@@ -79,9 +79,9 @@ import { basicAuth } from "hono/basic-auth";
7979
8080server .use (
8181 " *" ,
82- basicAuth ({ username: " hono" , password: " remix " }),
83- // Ensure Remix request handler is the last one
84- remix (options ),
82+ basicAuth ({ username: " hono" , password: " react-router " }),
83+ // Ensure React Router request handler is the last one
84+ reactRouter (options ),
8585);
8686```
8787
@@ -90,20 +90,18 @@ great of preview applications.
9090
9191## Session Management
9292
93- Additionally to the ` remix ` Hono middleware, there are other three middlewares
94- to work with Remix sessions.
93+ Additionally to the ` reactRouter ` Hono middleware, there are other three
94+ middlewares to work with React Router sessions.
9595
96- Because Remix sessions typically use a secret coming from the environment you
97- will need access to Hono ` c.env ` to use them. If you're using the Worker KV
96+ Because React Router sessions typically use a secret coming from the environment
97+ you will need access to Hono ` c.env ` to use them. If you're using the Worker KV
9898session storage you will also need to pass the KV binding to the middleware.
9999
100100You can use the different middlewares included in this package to do that:
101101
102102``` ts
103103import { session } from " remix-hono/session" ;
104- // Install the `@remix-run/*` package for your server adapter to grab the
105- // factory functions for session storage
106- import { createWorkerKVSessionStorage } from " @remix-run/cloudflare" ;
104+ import { createWorkerKVSessionStorage } from " @react-router/cloudflare" ;
107105
108106server .use (
109107 " *" ,
@@ -123,7 +121,7 @@ server.use(
123121);
124122```
125123
126- Now, setup the Remix middleware after your session middleware and use the
124+ Now, setup the React Router middleware after your session middleware and use the
127125helpers ` getSessionStorage ` and ` getSession ` to access the SessionStorage and
128126Session objects.
129127
@@ -136,7 +134,7 @@ import { getSessionStorage, getSession } from "remix-hono/session";
136134
137135server .use (
138136 " *" ,
139- remix <ContextEnv >({
137+ reactRouter <ContextEnv >({
140138 build ,
141139 mode: process .env .NODE_ENV as " development" | " production" ,
142140 // getLoadContext is optional, the default function is the same as here
@@ -205,32 +203,33 @@ If you're using Remix Hono with Cloudflare, you will need to serve your static
205203from the public folder (except for ` public/build ` ). The ` staticAssets `
206204middleware serves this purpose.
207205
208- First install ` @remix-run /cloudflare ` if you haven't installed it yet.
206+ First install ` @react-router /cloudflare ` if you haven't installed it yet.
209207
210208``` sh
211- npm add @remix-run /cloudflare
209+ npm add @react-router /cloudflare
212210```
213211
214212Then use the middleware in your server.
215213
216214``` ts
217215import { staticAssets } from " remix-hono/cloudflare" ;
218- import { remix } from " remix-hono/handler" ;
216+ import { reactRouter } from " remix-hono/handler" ;
219217
220218server .use (
221219 " *" ,
222220 staticAssets (),
223- // Add Remix request handler as the last middleware
224- remix (options ),
221+ // Add React Router request handler as the last middleware
222+ reactRouter (options ),
225223);
226224```
227225
228226## i18next integration
229227
230228If you're using [ remix-i18next] ( https://github.com/sergiodxa/remix-i18next ) to
231- support i18n in your Remix app, the ` i18next ` middleware let's you setup it for
232- your Remix app as a middleware that you can later use in your ` getLoadContext `
233- function to pass the ` locale ` and ` t ` functions to your loaders and actions.
229+ support i18n in your React Router app, the ` i18next ` middleware let's you setup
230+ it for your React Router app as a middleware that you can later use in your
231+ ` getLoadContext ` function to pass the ` locale ` and ` t ` functions to your loaders
232+ and actions.
234233
235234First install ` i18next ` and ` remix-i18next ` if you haven't already.
236235
@@ -253,7 +252,7 @@ functions using the helpers `i18next.getLocale` and `i18next.getFixedT`.
253252``` ts
254253server .use (
255254 " *" ,
256- remix ({
255+ reactRouter ({
257256 build ,
258257 mode: process .env .NODE_ENV as " development" | " production" ,
259258 // getLoadContext is optional, the default function is the same as here
0 commit comments