浏览代码

fix: 预览 /q/ 路径在 Vite dev proxy 中转发到 Express,避免 SPA 拦截

guoziyun 3 周之前
父节点
当前提交
3e68db8faa
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 4 0
      platform/client/vite.config.ts
  2. 3 1
      platform/server/src/index.ts

+ 4 - 0
platform/client/vite.config.ts

@@ -15,6 +15,10 @@ export default defineConfig({
         target: "http://localhost:3001",
         changeOrigin: true,
       },
+      "/q": {
+        target: "http://localhost:3001",
+        changeOrigin: true,
+      },
     },
   },
 });

+ 3 - 1
platform/server/src/index.ts

@@ -34,7 +34,9 @@ async function main() {
   app.use("/api/v1", previewRouter(db, STORAGE_DIR));
 
   // 构建预览文件(真机扫码测试)
-  app.use("/q", express.static(path.join(STORAGE_DIR, "previews")));
+  const previewsDir = path.join(STORAGE_DIR, "previews");
+  app.use("/q", express.static(previewsDir));
+  app.use("/q", (_req, res) => res.status(404).send("Preview not found"));
 
   // 生产环境:serve React 静态文件
   app.use(express.static(CLIENT_DIST));