Use proxy-safe relative URLs
This commit is contained in:
+15
-2
@@ -20,8 +20,16 @@ let page = 1;
|
|||||||
const pageSize = 20;
|
const pageSize = 20;
|
||||||
let polling: number | undefined;
|
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 = {}) {
|
function api(path: string, options: RequestInit = {}) {
|
||||||
return fetch(`/aishare/api${path}`, {
|
return fetch(new URL(`api${path}`, serviceBaseUrl()), {
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"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) {
|
function fmt(value: string | null) {
|
||||||
if (!value) return "";
|
if (!value) return "";
|
||||||
return new Date(value).toLocaleString();
|
return new Date(value).toLocaleString();
|
||||||
@@ -184,7 +197,7 @@ async function loadCaptures() {
|
|||||||
tbody.innerHTML = captures
|
tbody.innerHTML = captures
|
||||||
.map((capture) => {
|
.map((capture) => {
|
||||||
const title = capture.title || capture.slug || capture.sourceUrl;
|
const title = capture.title || capture.slug || capture.sourceUrl;
|
||||||
const link = capture.publicUrl || "";
|
const link = captureUrl(capture);
|
||||||
return `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
+2
-2
@@ -146,7 +146,7 @@ function pageScript(slug: string): string {
|
|||||||
return device + "-" + theme;
|
return device + "-" + theme;
|
||||||
}
|
}
|
||||||
function downloadShot(variant) {
|
function downloadShot(variant) {
|
||||||
location.href = "/aishare/${slug}/screenshots/" + variant + ".png";
|
location.href = "screenshots/" + variant + ".png";
|
||||||
}
|
}
|
||||||
var toastTimer;
|
var toastTimer;
|
||||||
function showToast(message) {
|
function showToast(message) {
|
||||||
@@ -240,7 +240,7 @@ export function renderConversationPage(slug: string, conversation: NormalizedCon
|
|||||||
</main>
|
</main>
|
||||||
<section class="downloads">
|
<section class="downloads">
|
||||||
<div class="downloads-inner">
|
<div class="downloads-inner">
|
||||||
<a class="icon-button" href="/aishare/${slug}/download" aria-label="Download export" title="Download export">${icons.download}</a>
|
<a class="icon-button" href="download" aria-label="Download export" title="Download export">${icons.download}</a>
|
||||||
<div class="shot-control">
|
<div class="shot-control">
|
||||||
<button class="icon-button shot-main" type="button" data-shot-current aria-label="Download screenshot" title="Download screenshot">${icons.image}</button>
|
<button class="icon-button shot-main" type="button" data-shot-current aria-label="Download screenshot" title="Download screenshot">${icons.image}</button>
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ function safeSendFrom(root: string, requested: string, res: Response): void {
|
|||||||
res.sendFile(target);
|
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.use(`${config.basePath}/admin-assets`, express.static(path.resolve("dist-client"), { immutable: true, maxAge: "1y" }));
|
||||||
|
|
||||||
app.get(`${config.basePath}/admin`, (_req, res) => {
|
app.get(`${config.basePath}/admin`, (_req, res) => {
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import { defineConfig } from "vite";
|
|||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
root: "client",
|
root: "client",
|
||||||
base: "/aishare/admin-assets/",
|
base: "./",
|
||||||
build: {
|
build: {
|
||||||
outDir: "../dist-client",
|
outDir: "../dist-client",
|
||||||
emptyOutDir: true
|
emptyOutDir: true
|
||||||
|
|||||||
Reference in New Issue
Block a user