fix: auto-detect base URL from window.location.origin
- public/test-api.html: value di baseUrl input kosong, apiBase() fallback ke window.location.origin, plus DOMContentLoaded listener utk auto-fill - api/test-api-content.ts: sama (legacy Next.js route) - Router.ts handleDocs() sudah pakai pendekatan ini sebelumnya
This commit is contained in:
1 parent
2f2aa08264
commit
d5f8dfc1d7
2 files changed
+8
-3
No files matched your search
@@ -1 +1,2 @@
|
|||||||
export default "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Edge Proxy — API Test</title>\n <style>\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n body { font-family: system-ui, -apple-system, sans-serif; background: #0d1117; color: #e1e4e8; padding: 1.5rem; }\n main { max-width: 960px; margin: 0 auto; }\n h1 { font-size: 1.5rem; colorLine truncated
|
export default "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Edge Proxy — API Test</title>\n <style>\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n body { font-family: system-ui, -apple-system, sans-serif; background: #0d1117; color: #e1e4e8; padding: 1.5rem; }\n main { max-width: 960px; margin: 0 auto; }\n h1 { font-size: 1.5rem; colorLine truncated
|
||||||
|
</script>\n</body>\n</html>\n";
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
<label>API Key (default: <code>sk-dummy-key</code>)</label>
|
<label>API Key (default: <code>sk-dummy-key</code>)</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<input type="text" id="apiKey" value="sk-dummy-key" />
|
<input type="text" id="apiKey" value="sk-dummy-key" />
|
||||||
<input type="text" id="baseUrl" value="http://localhost:3000" placeholder="http://localhost:3000" />
|
<input type="text" id="baseUrl" value="" placeholder="(same origin — auto-detected)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -141,7 +141,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
// --- Config ---
|
// --- Config ---
|
||||||
function apiBase() { return document.getElementById('baseUrl').value || 'http://localhost:3000'; }
|
function apiBase() { return document.getElementById('baseUrl').value || window.location.origin; }
|
||||||
function authHeaders() {
|
function authHeaders() {
|
||||||
const k = document.getElementById('apiKey').value || 'sk-dummy-key';
|
const k = document.getElementById('apiKey').value || 'sk-dummy-key';
|
||||||
return { 'Authorization': 'Bearer ' + k, 'Content-Type': 'application/json' };
|
return { 'Authorization': 'Bearer ' + k, 'Content-Type': 'application/json' };
|
||||||
@@ -351,6 +351,10 @@ function escapeHtml(s) {
|
|||||||
d.textContent = s;
|
d.textContent = s;
|
||||||
return d.innerHTML;
|
return d.innerHTML;
|
||||||
}
|
}
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const el = document.getElementById('baseUrl');
|
||||||
|
if (el && !el.value) el.value = window.location.origin;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in new issue
Block a user