forked from tinyslash-tech/tinyslash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-custom-domain.js
More file actions
116 lines (100 loc) · 3.19 KB
/
debug-custom-domain.js
File metadata and controls
116 lines (100 loc) · 3.19 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
/**
* Debug custom domain setup
*/
const { exec } = require('child_process');
const https = require('https');
async function debugCustomDomain() {
console.log('🔍 Debugging Custom Domain Setup\n');
const domain = 'links.pdfcircle.com';
const workerUrl = 'pebly.lahorivenkatesh709.workers.dev';
const testCode = '8X7Bx1';
console.log(`Domain: ${domain}`);
console.log(`Worker: ${workerUrl}`);
console.log(`Test Code: ${testCode}\n`);
// 1. Check DNS
console.log('1. 🌐 Checking DNS Configuration...');
try {
await execCommand(`dig ${domain} CNAME +short`);
} catch (error) {
console.log('❌ DNS check failed:', error.message);
}
// 2. Test Worker Health
console.log('\n2. 🔧 Testing Worker...');
try {
const workerResponse = await makeRequest(`https://${workerUrl}/health`);
console.log(`✅ Worker Health: ${workerResponse.status}`);
} catch (error) {
console.log('❌ Worker test failed:', error.message);
}
// 3. Test Backend Direct
console.log('\n3. 🖥️ Testing Backend Direct...');
try {
const backendResponse = await makeRequest(`https://urlshortner-1-hpyu.onrender.com/${testCode}`);
console.log(`Backend Response: ${backendResponse.status}`);
if (backendResponse.headers.location) {
console.log(`Redirect Location: ${backendResponse.headers.location}`);
}
} catch (error) {
console.log('❌ Backend test failed:', error.message);
}
// 4. Test Through Proxy
console.log('\n4. 🔄 Testing Through Proxy...');
try {
const proxyResponse = await makeRequest(`https://${workerUrl}/${testCode}`, {
'Host': domain
});
console.log(`Proxy Response: ${proxyResponse.status}`);
if (proxyResponse.headers.location) {
console.log(`Redirect Location: ${proxyResponse.headers.location}`);
}
} catch (error) {
console.log('❌ Proxy test failed:', error.message);
}
console.log('\n📋 Troubleshooting Steps:');
console.log('1. Verify DNS: dig links.pdfcircle.com CNAME');
console.log('2. Check if short code exists in your database');
console.log('3. Create a new test link with custom domain');
console.log('4. Wait 5-10 minutes for DNS propagation');
console.log('5. Test the new link');
}
function execCommand(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
} else {
console.log(stdout.trim() || 'No output');
resolve(stdout.trim());
}
});
});
}
function makeRequest(url, headers = {}) {
return new Promise((resolve, reject) => {
const urlObj = new URL(url);
const options = {
hostname: urlObj.hostname,
port: 443,
path: urlObj.pathname,
method: 'GET',
headers: {
'User-Agent': 'DebugTool/1.0',
...headers
}
};
const req = https.request(options, (res) => {
resolve({
status: res.statusCode,
headers: res.headers
});
});
req.on('error', reject);
req.setTimeout(10000, () => {
req.destroy();
reject(new Error('Request timeout'));
});
req.end();
});
}
debugCustomDomain().catch(console.error);