Bun
To deploy as a standalone Bun server, use the built-in bun adapter. This adapter uses Bun's native Bun.serve() API with edge-compatible fetch handlers and zero-copy static file serving.
You need Bun installed on your system:
curl -fsSL https://bun.sh/install | bash
No additional packages are needed - the adapter is built into @lazarv/react-server.
Then add the adapter to your react-server.config.mjs file:
export default {
adapter: "bun",
};
You can customize the adapter by passing options:
export default {
adapter: [
"bun",
{
name: "my-app", // Application name (used in generated package.json)
},
],
};
Configuration Options
name: Application name. Falls back topackage.jsonname (without scope) or "react-server-app".
Environment Variables
The generated server supports the following environment variables at runtime:
PORT: Server port (default:3000)HOST: Server hostname (default:0.0.0.0)ORIGIN: Override the origin URL for the server
The Bun adapter uses an edge build mode, bundling your entire server into a single file. At build time, it:
- Bundles your server code into
.bun/server/.react-server/server/edge.mjs - Copies all static assets into
.bun/static/ - Generates a
start.mjsscript with a build-time static route map that usesBun.serve({ static })for zero-copy static file serving - Creates a
package.jsonfor easy deployment
Static files (HTML, CSS, JS, images, etc.) are served directly by Bun's optimized static file handling without going through the fetch handler, giving you the best possible performance for static assets.
Build your application using the react-server CLI:
pnpm react-server build [root]
This produces a .bun/ directory with the following structure:
.bun/
├── start.mjs # Entry point with static route map
├── package.json # Deployment metadata
├── static/ # All static assets
│ ├── assets/ # Hashed build assets (CSS, JS)
│ ├── client/ # Client-side bundles
│ └── ... # Public files, pre-rendered HTML
└── server/
└── .react-server/
└── server/
└── edge.mjs # Bundled server
Start the production server directly:
bun .bun/start.mjs
Or use the --deploy flag to build and immediately start:
pnpm react-server build [root] --deploy
You can also use the generated package.json scripts:
cd .bun
bun start
Since the Bun adapter produces a self-contained server, you can deploy it anywhere Bun runs:
- Bare metal / VPS: Copy the
.bun/directory and runbun start.mjs - Docker: Use the official Bun Docker image
- Fly.io: Deploy with
flyctlusing a Dockerfile - Railway, Render: Point the start command to
bun .bun/start.mjs
Example Dockerfile
FROM oven/bun:latest
WORKDIR /app
COPY .bun/ .
EXPOSE 3000
CMD ["bun", "start.mjs"]