This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-apis.js
More file actions
88 lines (80 loc) · 2.51 KB
/
Copy pathtest-apis.js
File metadata and controls
88 lines (80 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require('dotenv').config();
const { MongoClient } = require('mongodb');
const cloudinary = require('cloudinary').v2;
const axios = require('axios');
// Configure Cloudinary
cloudinary.config({
cloud_name: 'dgaxmigyc',
api_key: '989384135426687',
api_secret: 'LYQMrzySO6kdR76UYhaX7rdg3ho'
});
async function testAPIs() {
console.log('Testing all API connections...\n');
// Test MongoDB
try {
console.log('1. Testing MongoDB connection...');
const client = new MongoClient(process.env.MONGODB_URI);
await client.connect();
await client.db().command({ ping: 1 });
console.log('✓ MongoDB connection successful!');
await client.close();
} catch (error) {
console.error('✗ MongoDB connection failed:', error.message);
}
// Test Cloudinary
try {
console.log('\n2. Testing Cloudinary connection...');
const result = await cloudinary.api.usage();
console.log('✓ Cloudinary connection successful!');
console.log(' Plan:', result.plan);
console.log(' Credits remaining:', result.credits.limit - result.credits.used_percent);
} catch (error) {
console.error('✗ Cloudinary connection failed:', error.error?.message || error.message);
}
// Test LaozHang API
try {
console.log('\n3. Testing LaozHang API connection...');
const response = await axios.post('https://api.laozhang.ai/v1/chat/completions', {
model: "sora_image",
messages: [
{
role: "system",
content: "You are a helpful assistant."
},
{
role: "user",
content: "Test connection"
}
]
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-JDMYnZIoNuIHnw560b1a618f3a1c4d2eA7778577012dAeF8'
}
});
console.log('✓ LaozHang API connection successful!');
if (response.data) {
console.log(' Response:', JSON.stringify(response.data, null, 2));
}
} catch (error) {
console.error('✗ LaozHang API connection failed:', error.response?.data || error.message);
console.error(' Full error:', error);
}
// Verify environment variables
console.log('\n4. Checking environment variables:');
const requiredEnvVars = [
'MONGODB_URI',
'CLOUDINARY_CLOUD_NAME',
'CLOUDINARY_API_KEY',
'CLOUDINARY_API_SECRET',
'JWT_SECRET'
];
for (const envVar of requiredEnvVars) {
if (process.env[envVar]) {
console.log(`✓ ${envVar} is set`);
} else {
console.log(`✗ ${envVar} is missing`);
}
}
}
testAPIs();