42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
const fetch = require('node-fetch');
|
|
require('dotenv').config({ path: '.env.local' });
|
|
require('dotenv').config({ path: '.env' });
|
|
|
|
const webhookUrl = process.env.N8N_WEBHOOK_URL || 'https://n8n.dk0.dev';
|
|
const fullUrl = `${webhookUrl}/webhook/chat`;
|
|
|
|
console.log(`Testing connection to: ${fullUrl}`);
|
|
|
|
async function testConnection() {
|
|
try {
|
|
const response = await fetch(fullUrl, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ message: "Hello from test script" })
|
|
});
|
|
|
|
console.log(`Status: ${response.status} ${response.statusText}`);
|
|
|
|
if (response.ok) {
|
|
const text = await response.text();
|
|
console.log('Response body:', text);
|
|
try {
|
|
const json = JSON.parse(text);
|
|
console.log('Parsed JSON:', json);
|
|
} catch (e) {
|
|
console.log('Could not parse response as JSON');
|
|
}
|
|
} else {
|
|
console.log('Response headers:', response.headers.raw());
|
|
const text = await response.text();
|
|
console.log('Error body:', text);
|
|
}
|
|
} catch (error) {
|
|
console.error('Connection failed:', error.message);
|
|
if (error.cause) console.error('Cause:', error.cause);
|
|
}
|
|
}
|
|
|
|
testConnection();
|