From d3bbd4220898fc6b98f5b98f31ff451e233fadc1 Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 9 Jul 2026 15:50:09 +0800 Subject: [PATCH] fix(web): optimize serveMainHtml performance by processing HTML at startup --- apps/web/src/index.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/web/src/index.ts b/apps/web/src/index.ts index e4fd4b03..12049077 100644 --- a/apps/web/src/index.ts +++ b/apps/web/src/index.ts @@ -89,17 +89,13 @@ async function run() { const mainHtmlHeaders = bundle.files.find((f) => f.path === bundle.index)?.headers || { 'content-type': 'text/html;charset=utf-8', } - let mainHtmlText = '' - const serveMainHtml = async () => { - if (!mainHtmlText) { - const raw = await mainHtmlFile.text() - mainHtmlText = raw - .replaceAll('href="./', 'href="/') - .replaceAll('src="./', 'src="/') - .replaceAll('content="./', 'content="/') - } - return new Response(mainHtmlText, { headers: mainHtmlHeaders }) - } + const raw = await mainHtmlFile.text() + const mainHtmlText = raw + .replaceAll('href="./', 'href="/') + .replaceAll('src="./', 'src="/') + .replaceAll('content="./', 'content="/') + const serveMainHtml = () => new Response(mainHtmlText, { headers: mainHtmlHeaders }) + routes['/'] = serveMainHtml routes['/*'] = serveMainHtml