Overview
Hyperscape uses Railway for production server deployment with automated GitHub Actions integration. The server handles both the game API and serves the frontend application.Production Architecture
Automated Deployment
GitHub Actions Workflow
The repository includes automated Railway deployment:Setup GitHub Actions
1
Generate Railway API token
- Go to Railway dashboard → Account Settings → Tokens
- Create new token with deployment permissions
- Copy the token
2
Add GitHub secret
- Go to GitHub repository → Settings → Secrets and variables → Actions
- Add new repository secret:
RAILWAY_TOKEN - Paste the Railway API token
3
Configure project IDs
Update Find these in Railway dashboard → Project → Settings → General
.github/workflows/deploy-railway.yml with your Railway IDs:Build Configuration
Nixpacks
Railway uses Nixpacks for building. Configuration innixpacks.toml:
Railway Configuration
Therailway.server.json file configures Railway deployment:
Environment Variables
Configure these in Railway dashboard → Variables:Required
Optional
Frontend Integration
The Railway deployment includes the frontend client:Build Process
- Build shared package - Core engine with ECS, Three.js, PhysX
- Build client package - React frontend with Vite
- Build server package - Fastify server with WebSocket support
- Copy client to server -
packages/client/dist/→packages/server/public/
Serving Strategy
The server serves both the API and the frontend:/- Frontend application (index.html)/api/*- REST API endpoints/ws- WebSocket connection/manifests/*- Game data manifests (fetched from CDN)/assets/*- Client assets (JS, CSS from built frontend)/status- Health check endpoint
Manifest Fetching
On server startup, manifests are fetched from the CDN:- Fetches all manifests from CDN at startup
- Compares with existing local files
- Only writes if content changed (avoids unnecessary disk I/O)
- Falls back to local manifests if CDN fetch fails
- Logs fetch results: “X fetched, Y updated, Z failed”
- Update game content by deploying new manifests to CDN
- No server redeployment needed for content changes
- Server always has latest game data
- Reduces deployment size
Deployment Verification
After deployment, verify the server is running:/status-{"status": "ok", ...}/- HTML content (frontend)/manifests/items.json- JSON manifest data/ws- WebSocket upgrade successful
Troubleshooting
Build Failures
Symptom: Railway build fails during build phase Common Causes:- Lockfile out of sync:
bun install && git add bun.lock - Missing environment variables: Check Railway dashboard
- Build timeout: Optimize build or upgrade Railway plan
- Railway dashboard → Deployments → View logs
- Look for specific error messages in build phase
Frontend Not Serving
Symptom: Server returns 503 “Frontend not available” Cause: Client build not copied to server’spublic/ directory
Solution: Verify nixpacks.toml includes:
Manifest Fetch Failures
Symptom: Server logs show “Failed to fetch manifests from CDN” Solutions:- Verify
PUBLIC_CDN_URLis set correctly in Railway variables - Test CDN accessibility:
curl $PUBLIC_CDN_URL/manifests/items.json - Check Railway logs for specific fetch errors
- Ensure manifests are deployed to CDN
CORS Errors
Symptom: Browser console shows CORS errors Cause: Frontend domain not in server’s CORS allowlist Solution: The server automatically allows:https://hyperscape.clubhttps://www.hyperscape.clubhttps://hyperscape.pages.devhttps://*.hyperscape.pages.devhttps://*.up.railway.app
PUBLIC_APP_URL environment variable in Railway.
Manual Deployment
If not using GitHub Actions, deploy manually:Monitoring
Railway Dashboard
Monitor deployment health:- Deployments → View build logs
- Metrics → CPU, memory, network usage
- Logs → Real-time server logs
Health Checks
Railway automatically monitors/status endpoint:
- Timeout: 300 seconds
- Restart policy: ON_FAILURE
- Max retries: 3