Skip to main content

Overview

While React Router provides adapters for common platforms, you can create custom server integrations for any environment that supports the Web Fetch API.

Core Concepts

All React Router server adapters use the same underlying pattern:
  1. Import your server build
  2. Create a request handler with createRequestHandler
  3. Convert platform requests to Web API Request objects
  4. Convert Web API Response objects back to platform responses

Basic Pattern

Here’s the general pattern for any server adapter:

Node.js HTTP Server

Create a custom Node.js server without using the @react-router/node package:

Deno Server

Create a server for Deno:

Bun Server

Create a server for Bun:

Custom Load Context

Pass platform-specific values to your routes:
Access in your routes:

Dynamic Build Import

For development, reload the build on each request:
For production, import once:

Mode Configuration

Pass the mode as the second parameter:
This affects:
  • Error stack traces (detailed in development)
  • Asset URLs and caching
  • Source maps

Streaming Responses

React Router uses streaming by default. Ensure your server supports streaming responses:

Static Asset Serving

Serve your built client assets:

Error Handling

Handle errors appropriately:

Request Abortion

Support request cancellation when the client disconnects:

Example Adapters

Refer to the official adapters for implementation examples:
  • Node.js: packages/react-router-node/server.ts
  • Cloudflare: packages/react-router-cloudflare/worker.ts
  • Express: packages/react-router-express/server.ts

Testing Your Adapter

  1. Build your application:
  2. Run your custom server:
  3. Test server-side rendering:
  4. Verify static assets load correctly
  5. Test dynamic routes and data loading
Custom servers must support the Web Fetch API (Request/Response). Modern runtimes like Node.js 18+, Deno, and Bun have built-in support.