From 3dca4ad77c4c04b0e95d0b392a77e306d339db60 Mon Sep 17 00:00:00 2001 From: suyx Date: Wed, 5 Aug 2026 11:22:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(POSTV1-01):=20=E5=9C=A8=E6=9C=80=E7=BB=88?= =?UTF-8?q?=E5=8C=85=E4=B8=AD=E6=8F=90=E4=BE=9B=E4=BA=A7=E5=93=81=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E4=B8=8E=E5=90=8C=E6=BA=90API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/app.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index 7623b3a..2f2fb95 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -1,5 +1,5 @@ import { randomBytes, randomUUID } from "node:crypto"; -import { createReadStream, readFileSync } from "node:fs"; +import { createReadStream, existsSync, readFileSync } from "node:fs"; import { resolve } from "node:path"; import { @@ -272,6 +272,10 @@ const supportGateDirectory = resolve(process.env.DADA_SUPPORT_GATE_ROOT ?? "apps const supportGateHtml = readFileSync(resolve(supportGateDirectory, "index.html"), "utf8"); const supportGateCss = readFileSync(resolve(supportGateDirectory, "support-gate.css"), "utf8"); const supportGateJavaScript = readFileSync(resolve(supportGateDirectory, "support-gate.js"), "utf8"); +const productWebRoot = resolve(process.env.DADA_WEB_ROOT ?? "apps/web/dist"); +const productIndexHtml = existsSync(resolve(productWebRoot, "index.html")) + ? readFileSync(resolve(productWebRoot, "index.html"), "utf8") + : undefined; const clientHints = "Sec-CH-UA, Sec-CH-UA-Full-Version-List, Sec-CH-UA-Platform"; const contentSecurityPolicy = [ "default-src 'self'", @@ -903,9 +907,15 @@ export async function createApp(options: CreateAppOptions = {}) { for (const route of ["/", "/app", "/app/*", "/admin", "/admin/*"]) { app.get(route, { schema: { hide: true } }, async (_request, reply) => { reply.type("text/html; charset=utf-8"); - return supportGateHtml; + return productIndexHtml ?? supportGateHtml; }); } + app.get("/assets/*", { schema: { hide: true } }, async (request, reply) => { + const relativePath = decodeURIComponent(request.url.split("?", 1)[0]!.slice("/assets/".length)); + const assetPath = resolve(productWebRoot, "assets", relativePath); + if (!assetPath.startsWith(resolve(productWebRoot, "assets")) || !existsSync(assetPath)) return reply.code(404).send(); + return reply.send(readFileSync(assetPath)); + }); app.get("/support-gate.css", { schema: { hide: true } }, async (_request, reply) => { reply.type("text/css; charset=utf-8"); return supportGateCss;