Complete guide to deploying NextReady applications to production with Vercel, environment configuration, and monitoring setup.
// vercel.json - Vercel Configuration
{
"buildCommand": "npm run build",
"outputDirectory": ".next",
"installCommand": "npm install",
"devCommand": "npm run dev",
"env": {
"NEXTAUTH_URL": "https://your-domain.vercel.app"
},
"build": {
"env": {
"DATABASE_URL": "@database-url",
"NEXTAUTH_SECRET": "@nextauth-secret",
"RESEND_API_KEY": "@resend-api-key"
}
},
"functions": {
"app/api/**": {
"maxDuration": 30
}
},
"regions": ["iad1"],
"framework": "nextjs"
}// scripts/deploy.js - Deployment Automation
const { execSync } = require('child_process');
const fs = require('fs');
const chalk = require('chalk');
class DeploymentManager {
constructor() {
this.environment = process.env.NODE_ENV || 'production';
this.branch = process.env.VERCEL_GIT_COMMIT_REF || 'main';
}
async run() {
console.log(chalk.blue.bold('š NextReady Deployment Pipeline\n'));
try {
await this.preDeploymentChecks();
await this.buildOptimization();
await this.databasePreparation();
await this.verifyDeployment();
console.log(chalk.green.bold('\nā
Deployment completed successfully!'));
} catch (error) {
console.error(chalk.red('Deployment failed:'), error.message);
process.exit(1);
}
}
async preDeploymentChecks() {
console.log(chalk.yellow('š Pre-deployment checks...'));
// Validate environment variables
const requiredEnvVars = [
'DATABASE_URL',
'NEXTAUTH_SECRET',
'NEXTAUTH_URL'
];
const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
if (missingVars.length > 0) {
throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
}
console.log(chalk.green('ā
Environment variables validated'));
// Test database connection
try {
execSync('npm run db:test', { stdio: 'pipe' });
console.log(chalk.green('ā
Database connection verified'));
} catch (error) {
throw new Error('Database connection failed');
}
// Run linting and type checking
try {
execSync('npm run lint', { stdio: 'pipe' });
console.log(chalk.green('ā
Linting passed'));
execSync('npm run type-check', { stdio: 'pipe' });
console.log(chalk.green('ā
Type checking passed'));
} catch (error) {
throw new Error('Code quality checks failed');
}
}
async buildOptimization() {
console.log(chalk.yellow('\nā” Build optimization...'));
// Clear previous builds
try {
execSync('rm -rf .next', { stdio: 'pipe' });
console.log(chalk.green('ā
Previous build cleared'));
} catch (error) {
// Ignore if .next doesn't exist
}
// Generate Prisma client
execSync('npx prisma generate', { stdio: 'inherit' });
console.log(chalk.green('ā
Prisma client generated'));
// Build application
execSync('npm run build', { stdio: 'inherit' });
console.log(chalk.green('ā
Application built successfully'));
}
async databasePreparation() {
console.log(chalk.yellow('\nšļø Database preparation...'));
if (this.branch === 'main' && this.environment === 'production') {
// Production database migrations
try {
execSync('npx prisma migrate deploy', { stdio: 'inherit' });
console.log(chalk.green('ā
Production migrations applied'));
} catch (error) {
throw new Error('Database migration failed');
}
} else {
// Development/preview environment
try {
execSync('npx prisma db push', { stdio: 'inherit' });
console.log(chalk.green('ā
Preview database schema updated'));
} catch (error) {
console.log(chalk.yellow('ā ļø Database schema update failed, continuing...'));
}
}
}
async verifyDeployment() {
console.log(chalk.yellow('\nā
Deployment verification...'));
// This would run after deployment
const deploymentUrl = process.env.VERCEL_URL ?
`https://${process.env.VERCEL_URL}` :
'http://localhost:3000';
console.log(chalk.cyan(`Deployment URL: ${deploymentUrl}`));
// Add health check logic here
console.log(chalk.green('ā
Deployment ready for verification'));
}
}
if (require.main === module) {
new DeploymentManager().run().catch(console.error);
}
module.exports = DeploymentManager;Your NextReady application is ready for production deployment. Follow the guide above to deploy securely and reliably.