A server-side rendered React application built with Bun, with Passkey Authentication support.
-
Server-Side Rendering (SSR): Initial HTML is rendered on the server for fast page loads and SEO benefits
-
Client-Side Routing: Smooth navigation between pages without full page reloads
-
React 19: Leverages the latest React features for optimal performance
-
Bun: Fast JavaScript runtime and bundler
-
WebAuthn/Passkey Authentication: Secure passwordless authentication using the WebAuthn standard
-
Configurable CORS: Cross-Origin Resource Sharing with support for specific domains or wildcards
The application uses React's renderToReadableStream
to render components on the server. This provides:
- Faster initial page loads
- Better SEO as search engines can crawl the fully rendered HTML
- Progressive enhancement (the site works even without JavaScript)
After the initial server render, the application hydrates on the client using React Router:
- The server renders the initial HTML with regular
<a>
links - The client-side JavaScript loads and hydrates the page
- React Router takes over navigation, providing a smooth SPA-like experience
- When a link is clicked, React Router handles the navigation without a full page reload
The application implements WebAuthn/Passkey authentication:
- Secure passwordless authentication
- Support for multiple authenticators
- Challenge-based authentication flow
For detailed information about the passkey implementation, see Passkey Documentation.
src/index.tsx
- Main server entry pointsrc/client.tsx
- Client-side entry point for hydrationsrc/components/
- React componentsHome.tsx
- Server-side rendered componentApp.tsx
- Client-side router layout component
src/routes/
- Server route handlersreact.tsx
- React SSR route handlerspasskey.ts
- Passkey authentication routesping.ts
- Health check routes
build.ts
- Build script for client-side JavaScriptpublic/
- Static assets and compiled client JavaScriptdocs/
- DocumentationROUTING.md
- Routing implementation detailsBUILD.md
- Build process documentationPASSKEY.md
- Passkey authentication documentationCORS.md
- CORS configuration documentation
The server handles these routes:
/
- Home page/react
- React demo page/client.js
- Serves the client-side JavaScript bundle/api/passkey/*
- Passkey authentication endpoints/api/ping
- Health check endpoint
Each React route renders the Home
component with different content.
For detailed information about the routing implementation, see Routing Documentation.
After hydration, React Router handles navigation between:
/
- Home page/react
- React demo page
The App
component provides the navigation UI, and the router renders different content based on the current URL.
- Bun 1.2.4 or higher
# Install dependencies
bun install
# Copy the example environment file and modify as needed
cp .env.example .env
# Build client-side JavaScript
bun run build.ts
# Start the server
bun run src/index.tsx
The server will start at http://localhost:3001.
For production, build the client with minification:
NODE_ENV=production bun run build.ts
PORT=8080 bun run src/index.tsx
The application uses environment variables for configuration. A .env.example
file is provided as a template.
Key environment variables include:
# Server configuration
PORT=3001
NODE_ENV=development
# WebAuthn configuration
RP_ID='["localhost", "your-domain.com"]'
RP_NAME='["App", "Your App Name"]'
EXPECTED_ORIGIN='["http://localhost:3001", "https://your-domain.com"]'
CHALLENGE_TTL_SECONDS=60
# CORS Configuration
ALLOWED_ORIGINS=https://your-domain.com,http://localhost:3001
The API supports configurable CORS settings. For detailed CORS configuration options, see CORS Documentation.
- Routing Implementation - Details about the routing implementation
- Build Process - Information about the build process
- Passkey Authentication - Documentation for the passkey authentication
- CORS Configuration - CORS configuration details
- Client Example - Example client implementation