Deployment
Deploy your CodeBaseHub application to production
Overview
CodeBaseHub can be deployed to various platforms. This guide covers the most popular options.
Warning: Make sure you have set up your production database and environment variables before deploying.
Vercel (Recommended)
Vercel is the recommended platform for deploying Next.js applications.
Steps
-
Connect Repository
- Go to Vercel
- Click "Add New Project"
- Import your Git repository
-
Configure Build Settings
Vercel automatically detects Next.js:
# Build Command pnpm build # Output Directory .next # Install Command pnpm install -
Set Environment Variables
DATABASE_URL=your-production-database-url AUTH_SECRET=your-secret-key AUTH_TRUST_HOST=true NEXT_PUBLIC_APP_URL=https://your-domain.com -
Deploy
Click "Deploy" and Vercel will build your application.
Custom Domain
- Go to project settings
- Navigate to "Domains"
- Add your custom domain
- Update DNS records as instructed
Railway
Railway provides easy deployment with databases.
Steps
-
Create Project
- Go to Railway
- Click "New Project"
- Select "Deploy from GitHub repo"
-
Add PostgreSQL
Railway automatically provisions a database and sets
DATABASE_URL. -
Set Environment Variables
AUTH_SECRET=your-secret-key AUTH_TRUST_HOST=true -
Deploy
Railway automatically deploys on every push.
Docker
Deploy using Docker for maximum flexibility.
Dockerfile
FROM node:18-alpine AS base
# Install dependencies
FROM base AS deps
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
# Build
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN corepack enable && pnpm build
# Production
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/apps/web/.next/standalone ./
COPY --from=builder /app/apps/web/.next/static ./apps/web/.next/static
EXPOSE 3000
CMD ["node", "apps/web/server.js"]Docker Compose
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://postgres:password@db:5432/myapp
- AUTH_SECRET=your-secret-key
depends_on:
- db
db:
image: postgres:15-alpine
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_DB=myapp
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:Commands
# Build
docker build -t codebasehub .
# Run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -fEnvironment Variables
Required
DATABASE_URL="postgresql://user:password@host:5432/database"
AUTH_SECRET="your-long-random-secret-key"
AUTH_TRUST_HOST="true"
NEXT_PUBLIC_APP_URL="https://your-domain.com"Optional
# OAuth
GITHUB_CLIENT_ID="..."
GITHUB_CLIENT_SECRET="..."
# Email
SMTP_HOST="smtp.example.com"
SMTP_USER="..."
SMTP_PASSWORD="..."Database Migration
Before deploying, run migrations:
# Generate migration
pnpm db:generate
# Push to production
pnpm db:pushPost-Deployment Checklist
- Application loads correctly
- Database connection works
- Authentication works
- Environment variables set
- Custom domain configured
- SSL certificate active
- Error tracking set up
Troubleshooting
Build Fails
Run pnpm type-check locally to find type errors.
Database Connection Errors
Verify DATABASE_URL is correct and accessible.
Authentication Not Working
Ensure AUTH_TRUST_HOST=true and NEXT_PUBLIC_APP_URL matches your domain.
Performance
Image Optimization
const nextConfig = {
images: {
domains: ['your-cdn.com'],
formats: ['image/avif', 'image/webp'],
},
};Caching
export const revalidate = 3600; // Revalidate every hour