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:
File diff suppressed because one or more lines are too long
@@ -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