import { ServerType } from "@hono/node-server"; import { Context, Env, Hono } from "hono"; import { AppLoadContext, RouterContextProvider, ServerBuild, UNSAFE_MiddlewareEnabled } from "react-router"; import { UpgradeWebSocket } from "hono/ws"; //#region src/types/hono-server-options-base.d.ts type ReactRouterHonoServerAppLoadContext = UNSAFE_MiddlewareEnabled extends true ? RouterContextProvider : AppLoadContext; interface HonoServerOptionsBase { /** * The base Hono app to use as a replacement for the default one created automatically * * It will be used to mount the React Router server on the `basename` path * defined in the [React Router config](https://api.reactrouter.com/v7/types/_react_router_dev.config.Config.html) * * {@link Hono} */ app?: Hono; /** * Enable the default logger * * Defaults to `true` */ defaultLogger?: boolean; /** * The port to start the server on * * Defaults to `process.env.PORT || 3000` */ port?: number; /** * Augment the React Router AppLoadContext * * Don't forget to declare the AppLoadContext in your app, next to where you create the Hono server * * ```ts * declare module "react-router" { * interface AppLoadContext { * // Add your custom context here * whatever: string; * } * } * ``` * * **To make the typing works correctly, in your `react-router.config.ts` or where you want, add future v8_middleware flag type to true.** * * ```ts * declare module "react-router" { * interface Future { * v8_middleware: true; // 👈 Enable middleware types * } * } * ``` */ getLoadContext?: (c: Context, options: { build: ServerBuild; mode: string; }) => Promise | ReactRouterHonoServerAppLoadContext; /** * Hook to add middleware that runs before any built-in middleware, including assets serving. * * You can use it to add protection middleware, for example. */ beforeAll?: (app: Hono) => Promise | void; } interface WithWebsocket { /** * Enable WebSockets support in `configure` * * For `bun` and `cloudflare` we will use the `@hono/node-ws`'s `injectWebSocket` on dev (only), * * Defaults to `false` */ useWebSocket: true; /** * Customize the Hono server, for example, adding middleware * * It is applied after the default middleware and before the React Router middleware */ configure: (app: Hono, options: { upgradeWebSocket: UpgradeWebSocket; }) => Promise | void; } interface WithoutWebsocket { /** * Enable WebSockets support in `configure` * * For `bun` and `cloudflare` we will use the `@hono/node-ws`'s `injectWebSocket` on dev (only), * * Defaults to `false` */ useWebSocket?: false | undefined; /** * Customize the Hono server, for example, adding middleware * * It is applied after the default middleware and before the React Router middleware */ configure?: (app: Hono) => Promise | void; } //#endregion //#region src/helpers.d.ts /** * Helper to create a getLoadContext function fully typed */ declare function createGetLoadContext(getLoadContext: HonoServerOptionsBase["getLoadContext"]): ((c: import("hono").Context, options: { build: ServerBuild; mode: string; }) => Promise | ReactRouterHonoServerAppLoadContext) | undefined; //#endregion export { WithoutWebsocket as i, HonoServerOptionsBase as n, WithWebsocket as r, createGetLoadContext as t };