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:- Import your server build
- Create a request handler with
createRequestHandler - Convert platform requests to Web API
Requestobjects - Convert Web API
Responseobjects 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:Dynamic Build Import
For development, reload the build on each request:Mode Configuration
Pass the mode as the second parameter:- 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
-
Build your application:
-
Run your custom server:
-
Test server-side rendering:
- Verify static assets load correctly
- 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.