Overview
The Hyperscape client automatically deploys to Cloudflare Pages on push to main via GitHub Actions. This provides:- Global CDN - Fast loading worldwide
- Automatic HTTPS - SSL certificates managed by Cloudflare
- Preview deployments - Every commit gets a preview URL
- Custom domains - hyperscape.gg, hyperscape.club
Automated Deployment
Workflow Trigger
The.github/workflows/deploy-pages.yml workflow triggers on:
packages/shared for packet definitions. When packets change on the server, the client must rebuild to stay in sync. This prevents “Missing packet handler” errors.
Example Scenario:
- Server adds new packet type (e.g.,
worldTimeSync) - Shared package exports new packet definition
- Client rebuild triggered automatically
- Client includes new packet handler
- No runtime errors
Deployment Steps
1. Checkout Code:--frozen-lockfile prevents npm rate-limiting by using only the committed lockfile.Multi-Line Commit Message Fix
Problem
Wrangler fails when commit messages contain newlines:Solution
Extract only the first line (commit 3e4bb48):- Extract first line with
head -1 - Remove quotes with
tr -d '"' - Truncate to 100 chars with
cut -c1-100
Production URLs
Primary Domain
- CNAME:
hyperscape.gg→hyperscape.pages.dev - Managed by Cloudflare Pages
Alternative Domain
Preview Deployments
Every commit gets a preview URL:Required GitHub Secrets
Configure in Settings → Secrets → Actions:Create Cloudflare API Token
- Go to Cloudflare Dashboard
- Navigate to My Profile → API Tokens
- Click Create Token
- Use Edit Cloudflare Workers template
- Add Account → Cloudflare Pages → Edit permission
- Copy token and add to GitHub Secrets
Environment Variables
Build-Time Variables
These are baked into the client build:Cloudflare Pages Dashboard
You can also set environment variables in the Cloudflare Pages dashboard:- Go to Pages → hyperscape → Settings → Environment variables
- Add variables for Production environment
- Trigger a new deployment
Manual Deployment
Using Wrangler CLI
Using GitHub Actions
Trigger manual deployment from GitHub UI:- Go to Actions tab
- Select “Deploy Client to Cloudflare Pages” workflow
- Click “Run workflow”
- Select branch (usually
main) - Choose environment (
productionorpreview) - Click “Run workflow”
Concurrency Control
The workflow uses concurrency control to prevent multiple deployments:- Only one deployment per branch at a time
- New deployment cancels in-progress deployment
- Prevents race conditions and wasted resources
Deployment Summary
After successful deployment, the workflow outputs:Troubleshooting
Build Failures
Check build logs:- Go to Actions tab in GitHub
- Click on failed workflow run
- Expand “Build client” step
- Check error messages
- Missing environment variables
- TypeScript errors
- Dependency resolution failures
- Out of memory (increase
NODE_OPTIONS)
Deployment Failures
Check wrangler logs:- Expand “Deploy to Cloudflare Pages” step
- Look for wrangler error messages
- Invalid
CLOUDFLARE_API_TOKEN - Project name mismatch
- Multi-line commit messages (fixed in commit 3e4bb48)
Preview URL Not Working
Check deployment status:- Go to Cloudflare Dashboard
- Navigate to Pages → hyperscape
- Check Deployments tab
- Verify deployment succeeded
- Deployment still in progress
- Build failed (check logs)
- DNS propagation delay (wait 5-10 minutes)
Assets Not Loading
Check CDN URL:CORS Errors
Problem: Client onhyperscape.gg cannot load assets from assets.hyperscape.club.
Solution: Configure R2 CORS (see R2 CORS Configuration).
R2 CORS Configuration
Automated Configuration
Thedeploy-cloudflare.yml workflow includes a CORS configuration step:
Manual Configuration
Verify CORS
CSP Configuration
Content Security Policy
The client includes CSP headers inpublic/_headers:
- Required for PhysX WASM loading
img-src 'self' data: https: blob:font-src 'self' data: https://fonts.gstatic.com
- Required for Rubik font
style-src 'self' 'unsafe-inline' https://fonts.googleapis.comfont-src 'self' data: https://fonts.gstatic.com
report-uri /api/csp-reportremoved (endpoint didn’t exist)
Vite Configuration
Node Polyfills Fix (commit e012ed2)
Problem: Production builds failed with “Failed to resolve module specifier” errors. Solution: Add aliases to resolve polyfill shims:Production Checklist
-
CLOUDFLARE_API_TOKENconfigured in GitHub Secrets -
PUBLIC_PRIVY_APP_IDconfigured in GitHub Secrets - R2 CORS configured for asset loading
- Custom domains configured in Cloudflare Pages dashboard
- CSP headers configured in
public/_headers - Environment variables set for production
- Build succeeds locally with
bun run build:client
Related Documentation
Deployment Guide
General deployment documentation
Configuration
Environment variables and settings
Troubleshooting
Common issues and solutions
Railway Deployment
Game server deployment