






















@@ -154,6 +154,21 @@ const CONTROL_UI_ROOT_PUBLIC_ASSETS = new Set([
154154"sw.js",
155155]);
156156157+/** Rewrites root-absolute Control UI public asset hrefs for configured base paths. */
158+export function rewriteControlUiIndexHtmlPublicAssetHrefs(html: string, basePath: string): string {
159+const normalized = normalizeControlUiBasePath(basePath);
160+if (!normalized) {
161+return html;
162+}
163+let next = html;
164+for (const asset of CONTROL_UI_ROOT_PUBLIC_ASSETS) {
165+const rootHref = `href="/${asset}"`;
166+const baseHref = `href="${normalized}/${asset}"`;
167+next = next.split(rootHref).join(baseHref);
168+}
169+return next;
170+}
171+157172type ControlUiAvatarResolution =
158173| { kind: "none"; reason: string; source?: string | null }
159174| { kind: "local"; filePath: string; source?: string | null }
@@ -743,8 +758,9 @@ function serveResolvedFile(res: ServerResponse, filePath: string, body: Buffer)
743758res.end(body);
744759}
745760746-function serveResolvedIndexHtml(res: ServerResponse, body: string) {
747-const hashes = computeInlineScriptHashes(body);
761+function serveResolvedIndexHtml(res: ServerResponse, body: string, basePath?: string) {
762+const prepared = rewriteControlUiIndexHtmlPublicAssetHrefs(body, basePath ?? "");
763+const hashes = computeInlineScriptHashes(prepared);
748764if (hashes.length > 0) {
749765res.setHeader(
750766"Content-Security-Policy",
@@ -753,7 +769,7 @@ function serveResolvedIndexHtml(res: ServerResponse, body: string) {
753769}
754770res.setHeader("Content-Type", "text/html; charset=utf-8");
755771res.setHeader("Cache-Control", "no-cache");
756-res.end(body);
772+res.end(prepared);
757773}
758774759775function readOpenedFile(fd: number): Promise<Buffer> {
@@ -1069,7 +1085,7 @@ export async function handleControlUiHttpRequest(
10691085return true;
10701086}
10711087if (path.basename(safeFile.path) === "index.html") {
1072-serveResolvedIndexHtml(res, await readOpenedFileText(safeFile.fd));
1088+serveResolvedIndexHtml(res, await readOpenedFileText(safeFile.fd), basePath);
10731089return true;
10741090}
10751091serveResolvedFile(res, safeFile.path, await readOpenedFile(safeFile.fd));
@@ -1097,7 +1113,7 @@ export async function handleControlUiHttpRequest(
10971113if (respondHeadForFile(req, res, safeIndex.path)) {
10981114return true;
10991115}
1100-serveResolvedIndexHtml(res, await readOpenedFileText(safeIndex.fd));
1116+serveResolvedIndexHtml(res, await readOpenedFileText(safeIndex.fd), basePath);
11011117return true;
11021118} finally {
11031119fs.closeSync(safeIndex.fd);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。