Sfoglia il codice sorgente

fix: 预览 URL 支持生产环境 nginx 代理

- previewService: 通过 PREVIEW_PUBLIC_URL 环境变量返回公网可达地址
- ecosystem.config.js: 配置预览公网地址为 /ads-preview/
- 本地开发默认仍用 localhost:5199
guoziyun 3 settimane fa
parent
commit
6687fe73b5

+ 1 - 0
ecosystem.config.js

@@ -7,6 +7,7 @@ module.exports = {
       env: {
       env: {
         NODE_ENV: "production",
         NODE_ENV: "production",
         PORT: 3001,
         PORT: 3001,
+        PREVIEW_PUBLIC_URL: "https://color2.jccytech.cn/ads-preview/",
       },
       },
       // 构建服务可能需要较多内存
       // 构建服务可能需要较多内存
       max_memory_restart: "512M",
       max_memory_restart: "512M",

+ 1 - 1
platform/server/dist/services/previewService.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"previewService.d.ts","sourceRoot":"","sources":["../../src/services/previewService.ts"],"names":[],"mappings":"AAoCA;;GAEG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAwC1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,UAAU,EAAE,MAAM,GACjB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAgBlC;AAED,wBAAgB,gBAAgB,IAAI;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAMrG"}
+{"version":3,"file":"previewService.d.ts","sourceRoot":"","sources":["../../src/services/previewService.ts"],"names":[],"mappings":"AAoCA;;GAEG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CA2C1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,UAAU,EAAE,MAAM,GACjB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAgBlC;AAED,wBAAgB,gBAAgB,IAAI;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAMrG"}

+ 5 - 2
platform/server/dist/services/previewService.js

@@ -73,10 +73,13 @@ async function startPreview(creativeId, theme, storageDir) {
     });
     });
     currentCreativeId = creativeId;
     currentCreativeId = creativeId;
     // 5. 等待 Vite 就绪
     // 5. 等待 Vite 就绪
+    const localUrl = `http://localhost:${PREVIEW_PORT}`;
     console.log("[preview] Waiting for Vite to be ready...");
     console.log("[preview] Waiting for Vite to be ready...");
-    await waitForReady(`http://localhost:${PREVIEW_PORT}`);
+    await waitForReady(localUrl);
     console.log("[preview] Vite is ready.");
     console.log("[preview] Vite is ready.");
-    return { url: `http://localhost:${PREVIEW_PORT}` };
+    // 生产环境通过 nginx 代理暴露公网 URL,本地开发直接用 localhost
+    const publicUrl = process.env.PREVIEW_PUBLIC_URL || localUrl;
+    return { url: publicUrl };
 }
 }
 /**
 /**
  * 更新预览配置(主题变更时调用)。Vite HMR 会自动检测并刷新页面。
  * 更新预览配置(主题变更时调用)。Vite HMR 会自动检测并刷新页面。

File diff suppressed because it is too large
+ 0 - 0
platform/server/dist/services/previewService.js.map


+ 5 - 2
platform/server/src/services/previewService.ts

@@ -76,11 +76,14 @@ export async function startPreview(
   currentCreativeId = creativeId;
   currentCreativeId = creativeId;
 
 
   // 5. 等待 Vite 就绪
   // 5. 等待 Vite 就绪
+  const localUrl = `http://localhost:${PREVIEW_PORT}`;
   console.log("[preview] Waiting for Vite to be ready...");
   console.log("[preview] Waiting for Vite to be ready...");
-  await waitForReady(`http://localhost:${PREVIEW_PORT}`);
+  await waitForReady(localUrl);
   console.log("[preview] Vite is ready.");
   console.log("[preview] Vite is ready.");
 
 
-  return { url: `http://localhost:${PREVIEW_PORT}` };
+  // 生产环境通过 nginx 代理暴露公网 URL,本地开发直接用 localhost
+  const publicUrl = process.env.PREVIEW_PUBLIC_URL || localUrl;
+  return { url: publicUrl };
 }
 }
 
 
 /**
 /**

Some files were not shown because too many files changed in this diff