Use proxy-safe relative URLs

This commit is contained in:
Codex
2026-07-08 06:24:02 +00:00
parent 65c1e8bddf
commit bbe7b6f562
4 changed files with 19 additions and 5 deletions
+15 -2
View File
@@ -20,8 +20,16 @@ let page = 1;
const pageSize = 20;
let polling: number | undefined;
function serviceBaseUrl() {
const url = new URL(location.href);
url.pathname = url.pathname.replace(/\/admin\/?$/, "/");
url.search = "";
url.hash = "";
return url;
}
function api(path: string, options: RequestInit = {}) {
return fetch(`/aishare/api${path}`, {
return fetch(new URL(`api${path}`, serviceBaseUrl()), {
...options,
headers: {
"content-type": "application/json",
@@ -31,6 +39,11 @@ function api(path: string, options: RequestInit = {}) {
});
}
function captureUrl(capture: Capture) {
if (capture.slug) return new URL(`${capture.slug}/`, serviceBaseUrl()).href;
return capture.publicUrl || "";
}
function fmt(value: string | null) {
if (!value) return "";
return new Date(value).toLocaleString();
@@ -184,7 +197,7 @@ async function loadCaptures() {
tbody.innerHTML = captures
.map((capture) => {
const title = capture.title || capture.slug || capture.sourceUrl;
const link = capture.publicUrl || "";
const link = captureUrl(capture);
return `
<tr>
<td>