worker: proxy /archive paths to replay origin

This commit is contained in:
every.channel 2026-02-24 03:32:19 -08:00
parent b570175e35
commit ee8c0b50d5
No known key found for this signature in database

View file

@ -108,7 +108,7 @@ export default {
// Archive replay proxy. Forwards website requests to an archive replay origin
// (typically forge running `ec-node wt-archive-serve`).
if (url.pathname.startsWith("/api/archive/")) {
if (url.pathname.startsWith("/api/archive/") || url.pathname.startsWith("/archive/")) {
const origin = env.EC_ARCHIVE_ORIGIN?.trim();
if (!origin) {
return jsonNoStore({ error: "archive origin not configured" }, { status: 503 });
@ -120,7 +120,9 @@ export default {
return jsonNoStore({ error: "invalid archive origin" }, { status: 500 });
}
const target = new URL(base.toString());
const suffix = url.pathname.slice("/api/archive".length);
const suffix = url.pathname.startsWith("/api/archive/")
? url.pathname.slice("/api/archive".length)
: url.pathname.slice("/archive".length);
target.pathname = `${base.pathname.replace(/\/$/, "")}/archive${suffix}`;
target.search = url.search;