All checks were successful
Build and Deploy Next.js Blog to Staging / 🔍 Code Quality Checks (push) Successful in 17s
Build and Deploy Next.js Blog to Staging / 🏗️ Build and Push Docker Image (push) Successful in 30s
PR Checks / lint-and-build (pull_request) Successful in 18s
Build and Deploy Next.js Blog to Staging / 🚀 Deploy to Staging (push) Successful in 47s
Build and Deploy Next.js Blog to Production / 🔍 Code Quality Checks (push) Successful in 17s
Build and Deploy Next.js Blog to Production / 🏗️ Build and Push Docker Image (push) Successful in 4s
Build and Deploy Next.js Blog to Production / 🚀 Deploy to Production (push) Successful in 47s
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
/**
|
|
* Environment variable validation for production builds
|
|
* Ensures all required environment variables are set before deployment
|
|
*/
|
|
|
|
const requiredEnvVars = ['NEXT_PUBLIC_SITE_URL', 'NODE_ENV'] as const
|
|
|
|
const _optionalEnvVars = ['PORT', 'HOSTNAME', 'NEXT_PUBLIC_GA_ID'] as const
|
|
|
|
export function validateEnvironment() {
|
|
const missingVars: string[] = []
|
|
|
|
// Check required variables
|
|
for (const varName of requiredEnvVars) {
|
|
if (!process.env[varName]) {
|
|
missingVars.push(varName)
|
|
}
|
|
}
|
|
|
|
if (missingVars.length > 0) {
|
|
console.error('❌ Missing required environment variables:')
|
|
missingVars.forEach(varName => {
|
|
console.error(` - ${varName}`)
|
|
})
|
|
console.error('\n💡 Check .env.example for reference')
|
|
throw new Error('Environment validation failed')
|
|
}
|
|
|
|
// Log configuration (safe - no secrets)
|
|
if (process.env.NODE_ENV === 'production') {
|
|
console.log('✅ Environment validation passed')
|
|
console.log(` - NEXT_PUBLIC_SITE_URL: ${process.env.NEXT_PUBLIC_SITE_URL}`)
|
|
console.log(` - PORT: ${process.env.PORT || '3030'}`)
|
|
}
|
|
}
|
|
|
|
// Run validation for production builds
|
|
if (process.env.NODE_ENV === 'production') {
|
|
validateEnvironment()
|
|
}
|