55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
// =====================================================
|
|
// 環境變數調試 API
|
|
// =====================================================
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
console.log('🔍 檢查 Next.js 中的環境變數...');
|
|
|
|
// 檢查所有相關的環境變數
|
|
const envVars = {
|
|
DB_HOST: process.env.DB_HOST,
|
|
DB_PORT: process.env.DB_PORT,
|
|
DB_NAME: process.env.DB_NAME,
|
|
DB_USER: process.env.DB_USER,
|
|
DB_PASSWORD: process.env.DB_PASSWORD ? '***' : undefined,
|
|
SLAVE_DB_HOST: process.env.SLAVE_DB_HOST,
|
|
SLAVE_DB_PORT: process.env.SLAVE_DB_PORT,
|
|
SLAVE_DB_NAME: process.env.SLAVE_DB_NAME,
|
|
SLAVE_DB_USER: process.env.SLAVE_DB_USER,
|
|
SLAVE_DB_PASSWORD: process.env.SLAVE_DB_PASSWORD ? '***' : undefined,
|
|
DB_DUAL_WRITE_ENABLED: process.env.DB_DUAL_WRITE_ENABLED,
|
|
DB_MASTER_PRIORITY: process.env.DB_MASTER_PRIORITY,
|
|
NODE_ENV: process.env.NODE_ENV,
|
|
};
|
|
|
|
console.log('📋 Next.js 環境變數檢查結果:');
|
|
Object.entries(envVars).forEach(([key, value]) => {
|
|
if (value) {
|
|
console.log(`✅ ${key}: ${value}`);
|
|
} else {
|
|
console.log(`❌ ${key}: undefined`);
|
|
}
|
|
});
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: '環境變數檢查完成',
|
|
data: {
|
|
envVars,
|
|
timestamp: new Date().toISOString(),
|
|
nodeEnv: process.env.NODE_ENV,
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error('❌ 環境變數檢查失敗:', error);
|
|
return NextResponse.json({
|
|
success: false,
|
|
message: '環境變數檢查失敗',
|
|
error: error instanceof Error ? error.message : '未知錯誤'
|
|
}, { status: 500 });
|
|
}
|
|
}
|