From bbe7b6f5621079706899b0c53c6cf630d81897e1 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 8 Jul 2026 06:24:02 +0000 Subject: [PATCH] Use proxy-safe relative URLs --- client/src/main.ts | 17 +++++++++++++++-- src/render.ts | 4 ++-- src/server.ts | 1 + vite.config.ts | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/client/src/main.ts b/client/src/main.ts index 7a4a62d..4eca0e2 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -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 ` diff --git a/src/render.ts b/src/render.ts index 7822332..d5109b2 100644 --- a/src/render.ts +++ b/src/render.ts @@ -146,7 +146,7 @@ function pageScript(slug: string): string { return device + "-" + theme; } function downloadShot(variant) { - location.href = "/aishare/${slug}/screenshots/" + variant + ".png"; + location.href = "screenshots/" + variant + ".png"; } var toastTimer; function showToast(message) { @@ -240,7 +240,7 @@ export function renderConversationPage(slug: string, conversation: NormalizedCon
- ${icons.download} + ${icons.download}
diff --git a/src/server.ts b/src/server.ts index ec72d0e..6336996 100644 --- a/src/server.ts +++ b/src/server.ts @@ -66,6 +66,7 @@ function safeSendFrom(root: string, requested: string, res: Response): void { res.sendFile(target); } +app.use(`${config.basePath}/assets`, express.static(path.resolve("dist-client/assets"), { immutable: true, maxAge: "1y" })); app.use(`${config.basePath}/admin-assets`, express.static(path.resolve("dist-client"), { immutable: true, maxAge: "1y" })); app.get(`${config.basePath}/admin`, (_req, res) => { diff --git a/vite.config.ts b/vite.config.ts index 7d1c4a6..5d1a1ad 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from "vite"; export default defineConfig({ root: "client", - base: "/aishare/admin-assets/", + base: "./", build: { outDir: "../dist-client", emptyOutDir: true