-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-fetch.html
More file actions
88 lines (73 loc) · 2.98 KB
/
test-fetch.html
File metadata and controls
88 lines (73 loc) · 2.98 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
<!DOCTYPE html>
<html>
<head>
<title>Fetch Test</title>
<style>
body { font-family: monospace; padding: 20px; }
.log { margin: 10px 0; padding: 10px; background: #f5f5f5; border-radius: 5px; }
.success { color: green; }
.error { color: red; }
</style>
</head>
<body>
<h1>GAS API Fetch 診斷</h1>
<div id="output"></div>
<script>
const output = document.getElementById('output');
function log(msg, type = 'info') {
const div = document.createElement('div');
div.className = `log ${type}`;
div.textContent = msg;
output.appendChild(div);
console.log(msg);
}
async function testFetch() {
const apiUrl = "https://script.google.com/macros/s/YOUR_DEPLOYMENT_ID/exec";
const token = "YOUR_API_TOKEN";
log(`1. Testing /health endpoint...`, 'info');
log(`URL: ${apiUrl}?path=health&token=${token.substring(0, 10)}...`, 'info');
try {
const response = await fetch(`${apiUrl}?path=health&token=${token}`, {
method: 'GET'
});
log(`Response Status: ${response.status}`, 'info');
log(`Response Headers:`, 'info');
for (const [key, value] of response.headers.entries()) {
log(` ${key}: ${value}`, 'info');
}
const text = await response.text();
log(`Response Body: ${text}`, response.ok ? 'success' : 'error');
try {
const json = JSON.parse(text);
log(`Parsed JSON: ${JSON.stringify(json, null, 2)}`, 'success');
} catch (e) {
log(`Failed to parse JSON: ${e.message}`, 'error');
}
} catch (error) {
log(`Fetch Error: ${error.message}`, 'error');
log(`Error Stack: ${error.stack}`, 'error');
}
log(`\n2. Testing /tasks endpoint...`, 'info');
try {
const response = await fetch(`${apiUrl}?path=tasks&token=${token}`, {
method: 'GET'
});
log(`Response Status: ${response.status}`, 'info');
const text = await response.text();
log(`Response Body Length: ${text.length} chars`, response.ok ? 'success' : 'error');
if (response.ok) {
try {
const json = JSON.parse(text);
log(`Parsed JSON - Tasks count: ${json.tasks?.length || 'N/A'}`, 'success');
} catch (e) {
log(`Failed to parse: ${e.message}`, 'error');
}
}
} catch (error) {
log(`Fetch Error: ${error.message}`, 'error');
}
}
window.addEventListener('DOMContentLoaded', testFetch);
</script>
</body>
</html>