Skip to content

Commit f11c4c6

Browse files
magnusmayclaudeautofix-ci[bot]
authored
docs: fix Bun server environment variable names and improve clarity (#5334)
Co-authored-by: Claude <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 6152c6e commit f11c4c6

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

docs/start/framework/react/hosting.md

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -269,20 +269,22 @@ export default defineConfig({
269269

270270
#### Production Server with Bun
271271

272-
Alternatively, you can use a custom server implementation.
272+
Alternatively, you can use a custom server implementation that leverages Bun's native APIs.
273273

274-
We've created an optimized production server that provides intelligent static asset loading with configurable memory management.
274+
We provide a reference implementation that demonstrates one approach to building a production-ready Bun server. This example uses Bun-native functions for optimal performance and includes features like intelligent asset preloading and memory management.
275275

276-
**Features:**
276+
**This is a starting point - feel free to adapt it to your needs or simplify it for your use case.**
277277

278-
- **Hybrid loading strategy**: Small files (<5MB by default) are preloaded into memory, large files are served on-demand
279-
- **Configurable file filtering**: Use include/exclude patterns to control which files are preloaded
280-
- **Production-ready caching headers**: Automatic optimization for static assets
281-
- **Memory-efficient**: Smart memory management prevents excessive RAM usage
278+
**What this example demonstrates:**
279+
280+
- Serving static assets using Bun's native file handling
281+
- Hybrid loading strategy (preload small files, serve large files on-demand)
282+
- Optional features like ETag support and Gzip compression
283+
- Production-ready caching headers
282284

283285
**Quick Setup:**
284286

285-
1. Copy the [`server.ts`](https://github.com/tanstack/router/blob/main/examples/react/start-bun/server.ts) file from the example in this repository to your project root
287+
1. Copy the [`server.ts`](https://github.com/tanstack/router/blob/main/examples/react/start-bun/server.ts) file from the example repository to your project root (or use it as inspiration for your own implementation)
286288

287289
2. Build your application:
288290

@@ -296,36 +298,57 @@ We've created an optimized production server that provides intelligent static as
296298
bun run server.ts
297299
```
298300

299-
**Configuration:**
301+
**Configuration (Optional):**
300302

301-
The server can be configured using environment variables:
303+
The reference server implementation includes several optional configuration options via environment variables. You can use these as-is, modify them, or remove features you don't need:
302304

303305
```sh
304-
# Basic usage
306+
# Basic usage - just works out of the box
305307
bun run server.ts
306308

307-
# Custom port
308-
PORT=8080 bun run server.ts
309+
# Common configurations
310+
PORT=8080 bun run server.ts # Custom port
311+
ASSET_PRELOAD_VERBOSE_LOGGING=true bun run server.ts # See what's happening
312+
```
313+
314+
**Available Environment Variables:**
315+
316+
| Variable | Description | Default |
317+
| -------------------------------- | -------------------------------------------------- | ----------------------------------------------------------------------------- |
318+
| `PORT` | Server port | `3000` |
319+
| `ASSET_PRELOAD_MAX_SIZE` | Maximum file size to preload into memory (bytes) | `5242880` (5MB) |
320+
| `ASSET_PRELOAD_INCLUDE_PATTERNS` | Comma-separated glob patterns for files to include | All files |
321+
| `ASSET_PRELOAD_EXCLUDE_PATTERNS` | Comma-separated glob patterns for files to exclude | None |
322+
| `ASSET_PRELOAD_VERBOSE_LOGGING` | Enable detailed logging | `false` |
323+
| `ASSET_PRELOAD_ENABLE_ETAG` | Enable ETag generation | `true` |
324+
| `ASSET_PRELOAD_ENABLE_GZIP` | Enable Gzip compression | `true` |
325+
| `ASSET_PRELOAD_GZIP_MIN_SIZE` | Minimum file size for Gzip (bytes) | `1024` (1KB) |
326+
| `ASSET_PRELOAD_GZIP_MIME_TYPES` | MIME types eligible for Gzip | `text/,application/javascript,application/json,application/xml,image/svg+xml` |
327+
328+
<details>
329+
<summary>Advanced configuration examples</summary>
309330

310-
# Optimize for minimal memory usage (1MB preload limit)
311-
STATIC_PRELOAD_MAX_BYTES=1048576 bun run server.ts
331+
```sh
332+
# Optimize for minimal memory usage
333+
ASSET_PRELOAD_MAX_SIZE=1048576 bun run server.ts
312334

313335
# Preload only critical assets
314-
STATIC_PRELOAD_INCLUDE="*.js,*.css" \
315-
STATIC_PRELOAD_EXCLUDE="*.map,vendor-*" \
336+
ASSET_PRELOAD_INCLUDE_PATTERNS="*.js,*.css" \
337+
ASSET_PRELOAD_EXCLUDE_PATTERNS="*.map,vendor-*" \
316338
bun run server.ts
317339

318-
# Debug mode with verbose logging
319-
STATIC_PRELOAD_VERBOSE=true bun run server.ts
320-
```
340+
# Disable optional features
341+
ASSET_PRELOAD_ENABLE_ETAG=false \
342+
ASSET_PRELOAD_ENABLE_GZIP=false \
343+
bun run server.ts
321344

322-
**Environment Variables:**
345+
# Custom Gzip configuration
346+
ASSET_PRELOAD_GZIP_MIN_SIZE=2048 \
347+
ASSET_PRELOAD_GZIP_MIME_TYPES="text/,application/javascript,application/json" \
348+
bun run server.ts
349+
```
323350

324-
- `PORT`: Server port (default: 3000)
325-
- `STATIC_PRELOAD_MAX_BYTES`: Maximum file size to preload in bytes (default: 5242880 = 5MB)
326-
- `STATIC_PRELOAD_INCLUDE`: Comma-separated glob patterns for files to include
327-
- `STATIC_PRELOAD_EXCLUDE`: Comma-separated glob patterns for files to exclude
328-
- `STATIC_PRELOAD_VERBOSE`: Enable detailed logging (set to "true")
351+
</details>
329352

330353
**Example Output:**
331354

0 commit comments

Comments
 (0)