-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello-world.html
More file actions
79 lines (71 loc) · 3.45 KB
/
hello-world.html
File metadata and controls
79 lines (71 loc) · 3.45 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
---
layout: default
title: Hello World
permalink: /hello-world/
---
{% assign active_lang = site.active_lang | default: site.default_lang | default: 'en' %}
{% assign t = site.data[active_lang].ui %}
<div class="max-w-7xl mx-auto px-6 py-16">
<div class="glass-panel p-8 md:p-10 rounded-3xl border border-surface-border max-w-3xl">
<h1 class="text-3xl font-display font-bold text-[var(--text-base)] mb-3">{{ t.hello_world.title | default: 'Hello World (API)' }}</h1>
<p class="text-muted text-sm leading-relaxed mb-8">{{ t.hello_world.lead | default: 'GET /api/hello-world via Cloudflare Functions; requires Bearer token.' }}</p>
<div class="flex flex-wrap gap-3 mb-6">
<button type="button" id="hw-call" class="px-5 py-2.5 rounded-full bg-coderic-600 text-white text-sm font-semibold hover:bg-coderic-500 transition-colors">
{{ t.hello_world.btn | default: 'Call /api/hello-world' }}
</button>
<button type="button" id="hw-call-no-auth" class="px-5 py-2.5 rounded-full border border-surface-border text-sm font-medium text-muted hover:bg-surface-panel transition-colors">
{{ t.hello_world.btn_probe | default: 'GET without Bearer (expect 401)' }}
</button>
</div>
<div class="space-y-4">
<div>
<p class="text-xs font-bold text-muted uppercase tracking-wider mb-1">{{ t.hello_world.status_label | default: 'HTTP status' }}</p>
<p id="hw-status" class="text-lg font-mono text-coderic-500">—</p>
</div>
<div>
<p class="text-xs font-bold text-muted uppercase tracking-wider mb-1">{{ t.hello_world.body_label | default: 'JSON response' }}</p>
<pre id="hw-body" class="text-xs font-mono bg-surface-panel/80 border border-surface-border rounded-xl p-4 overflow-x-auto whitespace-pre-wrap min-h-[120px] text-[var(--text-base)]">—</pre>
</div>
</div>
</div>
</div>
<script>
(function () {
const lblLoading = {{ t.hello_world.loading | default: 'Requesting...' | jsonify }};
const lblNoToken = {{ t.hello_world.no_token | default: 'No access token. Sign in first.' | jsonify }};
const statusEl = document.getElementById('hw-status');
const bodyEl = document.getElementById('hw-body');
async function doFetch(withBearer) {
statusEl.textContent = '\u2014';
bodyEl.textContent = lblLoading;
const headers = {};
if (withBearer) {
if (typeof codericGetAuth0Client !== 'function') {
statusEl.textContent = '\u2014';
bodyEl.textContent = lblNoToken;
return;
}
const client = await codericGetAuth0Client();
try { await client.checkSession(); } catch {}
const authed = await client.isAuthenticated();
if (!authed) {
statusEl.textContent = '\u2014';
bodyEl.textContent = lblNoToken;
return;
}
const token = await client.getTokenSilently();
headers['Authorization'] = 'Bearer ' + token;
}
const res = await fetch('/api/hello-world', { headers });
statusEl.textContent = String(res.status);
const text = await res.text();
try {
bodyEl.textContent = JSON.stringify(JSON.parse(text), null, 2);
} catch {
bodyEl.textContent = text || '(empty)';
}
}
document.getElementById('hw-call').addEventListener('click', function () { doFetch(true); });
document.getElementById('hw-call-no-auth').addEventListener('click', function () { doFetch(false); });
})();
</script>