Explorar o código

debug: log HTML rewrite details in previewProxy

guoziyun hai 3 semanas
pai
achega
329da464d8

+ 1 - 1
platform/server/dist/middleware/previewProxy.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"previewProxy.d.ts","sourceRoot":"","sources":["../../src/middleware/previewProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAmB5C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CA8E9D"}
+{"version":3,"file":"previewProxy.d.ts","sourceRoot":"","sources":["../../src/middleware/previewProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAmB5C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CAmF9D"}

+ 4 - 0
platform/server/dist/middleware/previewProxy.js

@@ -50,6 +50,7 @@ function previewProxy(req, res) {
     }, (proxyRes) => {
     }, (proxyRes) => {
         const contentType = (proxyRes.headers["content-type"] || "");
         const contentType = (proxyRes.headers["content-type"] || "");
         const isHtml = contentType.includes("text/html");
         const isHtml = contentType.includes("text/html");
+        console.log(`[preview:proxy] response ${proxyRes.statusCode} content-type=${contentType} isHtml=${isHtml}`);
         // 复制响应 headers(过滤 hop-by-hop)
         // 复制响应 headers(过滤 hop-by-hop)
         const resHeaders = {};
         const resHeaders = {};
         for (const [key, value] of Object.entries(proxyRes.headers)) {
         for (const [key, value] of Object.entries(proxyRes.headers)) {
@@ -68,6 +69,9 @@ function previewProxy(req, res) {
                 // 将 src="/..." 和 href="/..." 重写为 /ads/preview/...
                 // 将 src="/..." 和 href="/..." 重写为 /ads/preview/...
                 // 匹配 root-absolute 路径:以 / 开头,后跟非 / 字符(避免匹配 //)
                 // 匹配 root-absolute 路径:以 / 开头,后跟非 / 字符(避免匹配 //)
                 html = html.replace(/(src|href)="\/([^/][^"]*)"/g, '$1="/ads/preview/$2"');
                 html = html.replace(/(src|href)="\/([^/][^"]*)"/g, '$1="/ads/preview/$2"');
+                // 日志:检查重写后的 @vite/client 行
+                const viteClientMatch = html.match(/src="[^"]*@vite\/client[^"]*"/);
+                console.log(`[preview:proxy] HTML vite/client: ${viteClientMatch?.[0] || "NOT FOUND"}`);
                 const body = Buffer.from(html, "utf-8");
                 const body = Buffer.from(html, "utf-8");
                 resHeaders["content-type"] = "text/html; charset=utf-8";
                 resHeaders["content-type"] = "text/html; charset=utf-8";
                 resHeaders["content-length"] = String(body.length);
                 resHeaders["content-length"] = String(body.length);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
platform/server/dist/middleware/previewProxy.js.map


+ 5 - 0
platform/server/src/middleware/previewProxy.ts

@@ -49,6 +49,7 @@ export function previewProxy(req: Request, res: Response): void {
     (proxyRes) => {
     (proxyRes) => {
       const contentType = (proxyRes.headers["content-type"] || "") as string;
       const contentType = (proxyRes.headers["content-type"] || "") as string;
       const isHtml = contentType.includes("text/html");
       const isHtml = contentType.includes("text/html");
+      console.log(`[preview:proxy] response ${proxyRes.statusCode} content-type=${contentType} isHtml=${isHtml}`);
 
 
       // 复制响应 headers(过滤 hop-by-hop)
       // 复制响应 headers(过滤 hop-by-hop)
       const resHeaders: Record<string, string> = {};
       const resHeaders: Record<string, string> = {};
@@ -74,6 +75,10 @@ export function previewProxy(req: Request, res: Response): void {
             '$1="/ads/preview/$2"',
             '$1="/ads/preview/$2"',
           );
           );
 
 
+          // 日志:检查重写后的 @vite/client 行
+          const viteClientMatch = html.match(/src="[^"]*@vite\/client[^"]*"/);
+          console.log(`[preview:proxy] HTML vite/client: ${viteClientMatch?.[0] || "NOT FOUND"}`);
+
           const body = Buffer.from(html, "utf-8");
           const body = Buffer.from(html, "utf-8");
           resHeaders["content-type"] = "text/html; charset=utf-8";
           resHeaders["content-type"] = "text/html; charset=utf-8";
           resHeaders["content-length"] = String(body.length);
           resHeaders["content-length"] = String(body.length);

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio