Skip to main content

Overview

BeeHex is a Next.js 14 application optimized for deployment on modern hosting platforms. This guide covers deployment options, configuration, and best practices.

Prerequisites

Before deploying, ensure:
  • Your code is committed to a Git repository
  • All tests pass locally
  • Production environment variables are configured
  • Game server backend is deployed and accessible

Deployment Options

Vercel is the recommended platform for deploying BeeHex, created by the makers of Next.js.
1

Connect Repository

  1. Go to vercel.com
  2. Click “New Project”
  3. Import your BeeHex repository
2

Configure Project

Vercel auto-detects Next.js projects. Verify settings:
  • Framework Preset: Next.js
  • Build Command: npm run build
  • Output Directory: .next
  • Install Command: npm install
3

Set Environment Variables

Add production environment variables:
Since BeeHex uses src/env/env.ts for configuration, you’ll need to modify this file or use a build-time script to inject production values.
4

Deploy

Click “Deploy”. Vercel will:
  • Install dependencies
  • Build your Next.js application
  • Deploy to a global CDN
  • Provide a production URL
Deployment typically takes 2-3 minutes.

Vercel Features

Automatic Deployments

Every push to your main branch triggers a new deployment

Preview Deployments

Pull requests get unique preview URLs for testing

Edge Network

Global CDN for fast loading worldwide

Zero Configuration

Automatic optimization for Next.js apps

Netlify

Deploy BeeHex on Netlify with automatic builds:
1

Create New Site

  1. Log in to netlify.com
  2. Click “Add new site” → “Import an existing project”
  3. Connect your Git repository
2

Configure Build Settings

3

Add Environment Variables

In Site settings → Environment variables, configure your production settings.
4

Deploy

Click “Deploy site” to trigger your first deployment.
Netlify provides automatic HTTPS, continuous deployment, and branch previews.

Docker Container

Deploy BeeHex as a Docker container for self-hosted environments:
1

Create Dockerfile

Create a Dockerfile in your project root:
Dockerfile
2

Build Docker Image

3

Run Container

4

(Optional) Use Docker Compose

Create docker-compose.yml:
docker-compose.yml
Run with:

Traditional Hosting (VPS)

Deploy on a VPS (DigitalOcean, AWS EC2, etc.):
1

Prepare Server

Install Node.js 20+ on your server:
2

Clone Repository

3

Install Dependencies

4

Configure Environment

Create production environment configuration:
src/env/env.ts
5

Build Application

6

Start with PM2

Use PM2 for process management:
7

Configure Nginx Reverse Proxy

Create Nginx configuration:
/etc/nginx/sites-available/beehex
Enable site:
8

Setup SSL with Let's Encrypt

Build Optimization

Production Build

Create an optimized production build:
This command:
  • Compiles TypeScript to JavaScript
  • Minifies JavaScript and CSS
  • Optimizes images and fonts
  • Generates static pages where possible
  • Creates production bundles in .next/

Build Output

Environment Configuration

Production Environment

For production, modify src/env/env.ts:
Important: The current environment system uses a gitignored file. Consider implementing a build-time environment variable system for easier deployment:

Environment Variable Best Practices

  1. Never commit secrets to version control
  2. Use different values for development, staging, and production
  3. Prefix client-side variables with NEXT_PUBLIC_ in Next.js
  4. Document all required variables in your README

Performance Optimization

Next.js Optimizations

BeeHex leverages Next.js built-in optimizations:

Automatic Code Splitting

Each route only loads necessary code

Image Optimization

Automatic image resizing and WebP conversion

Font Optimization

Self-hosted fonts with zero layout shift

Script Optimization

Optimized third-party script loading

Additional Optimizations

1

Enable Compression

Next.js automatically gzip/brotli compresses responses in production.
2

Configure Caching

Set appropriate cache headers for static assets:
next.config.mjs
3

Analyze Bundle Size

Update next.config.mjs:
Run analysis:

Monitoring & Logging

Application Monitoring

Monitor your production deployment:
  • Vercel Analytics: Built-in analytics for Vercel deployments
  • Google Analytics: Track user behavior
  • Sentry: Error tracking and performance monitoring
  • LogRocket: Session replay and debugging

Health Checks

Implement health check endpoints:
src/app/api/health/route.ts

Rollback Strategy

Vercel Rollback

  1. Go to your project dashboard
  2. Click “Deployments”
  3. Find the previous working deployment
  4. Click ”⋯” → “Promote to Production”

Manual Rollback

Continuous Deployment

GitHub Actions

Automate deployments with GitHub Actions:
.github/workflows/deploy.yml

Security Considerations

Production Checklist:
  • ✅ Use HTTPS for all connections
  • ✅ Configure secure WebSocket connections (WSS)
  • ✅ Set secure headers (CSP, HSTS, X-Frame-Options)
  • ✅ Enable rate limiting on API routes
  • ✅ Sanitize user inputs
  • ✅ Keep dependencies up to date
  • ✅ Monitor for security vulnerabilities

Security Headers

Add security headers in next.config.mjs:

Troubleshooting

Build Fails

Issue: Build fails with TypeScript errors

WebSocket Connection Issues

Issue: Can’t connect to game server in production
  1. Verify IP_HOST in src/env/env.ts points to production server
  2. Ensure game server allows connections from your domain
  3. Check CORS configuration on game server
  4. Use WSS (secure WebSocket) for HTTPS sites

Memory Issues

Issue: Build runs out of memory

Next Steps

Architecture Overview

Understand the system architecture

Game Engine

Learn about the game engine implementation

WebSocket Protocol

Explore the real-time communication protocol

Contributing

Contribute to the project