fix: Add n8n environment variables to production deployment
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Failing after 10m24s
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Failing after 10m24s
- Add N8N_WEBHOOK_URL, N8N_SECRET_TOKEN, N8N_API_KEY to docker-compose.production.yml - Export environment variables in workflow before docker-compose up - Improve error logging in chat API for better debugging - Add better error handling in ChatWidget component - Create setup guide for n8n chat configuration
This commit is contained in:
@@ -30,15 +30,24 @@ export async function POST(request: NextRequest) {
|
||||
// Call your n8n chat webhook
|
||||
const n8nWebhookUrl = process.env.N8N_WEBHOOK_URL;
|
||||
|
||||
if (!n8nWebhookUrl) {
|
||||
console.error("N8N_WEBHOOK_URL not configured");
|
||||
if (!n8nWebhookUrl || n8nWebhookUrl.trim() === '') {
|
||||
console.error("N8N_WEBHOOK_URL not configured. Environment check:", {
|
||||
hasUrl: !!process.env.N8N_WEBHOOK_URL,
|
||||
urlValue: process.env.N8N_WEBHOOK_URL || '(empty)',
|
||||
nodeEnv: process.env.NODE_ENV,
|
||||
});
|
||||
return NextResponse.json({
|
||||
reply: getFallbackResponse(userMessage),
|
||||
});
|
||||
}
|
||||
|
||||
const webhookUrl = `${n8nWebhookUrl}/webhook/chat`;
|
||||
console.log(`Sending to n8n: ${webhookUrl}`);
|
||||
// Ensure URL doesn't have trailing slash before adding /webhook/chat
|
||||
const baseUrl = n8nWebhookUrl.replace(/\/$/, '');
|
||||
const webhookUrl = `${baseUrl}/webhook/chat`;
|
||||
console.log(`Sending to n8n: ${webhookUrl}`, {
|
||||
hasSecretToken: !!process.env.N8N_SECRET_TOKEN,
|
||||
hasApiKey: !!process.env.N8N_API_KEY,
|
||||
});
|
||||
|
||||
// Add timeout to prevent hanging requests
|
||||
const controller = new AbortController();
|
||||
@@ -67,8 +76,13 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
console.error(`n8n webhook failed with status: ${response.status}`, errorText);
|
||||
throw new Error(`n8n webhook failed: ${response.status} - ${errorText}`);
|
||||
console.error(`n8n webhook failed with status: ${response.status}`, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
error: errorText,
|
||||
webhookUrl: webhookUrl.replace(/\/\/[^:]+:[^@]+@/, '//***:***@'), // Hide credentials in logs
|
||||
});
|
||||
throw new Error(`n8n webhook failed: ${response.status} - ${errorText.substring(0, 200)}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
@@ -198,7 +212,10 @@ export async function POST(request: NextRequest) {
|
||||
console.error("Error details:", {
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
n8nUrl: process.env.N8N_WEBHOOK_URL ? 'configured' : 'missing',
|
||||
n8nUrl: process.env.N8N_WEBHOOK_URL ? `configured (${process.env.N8N_WEBHOOK_URL})` : 'missing',
|
||||
hasSecretToken: !!process.env.N8N_SECRET_TOKEN,
|
||||
hasApiKey: !!process.env.N8N_API_KEY,
|
||||
nodeEnv: process.env.NODE_ENV,
|
||||
});
|
||||
|
||||
// Fallback to mock responses
|
||||
|
||||
Reference in New Issue
Block a user