fix(POSTV1-01): 在最终包中提供产品网页与同源API
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
This commit is contained in:
+12
-2
@@ -1,5 +1,5 @@
|
|||||||
import { randomBytes, randomUUID } from "node:crypto";
|
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 { resolve } from "node:path";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -272,6 +272,10 @@ const supportGateDirectory = resolve(process.env.DADA_SUPPORT_GATE_ROOT ?? "apps
|
|||||||
const supportGateHtml = readFileSync(resolve(supportGateDirectory, "index.html"), "utf8");
|
const supportGateHtml = readFileSync(resolve(supportGateDirectory, "index.html"), "utf8");
|
||||||
const supportGateCss = readFileSync(resolve(supportGateDirectory, "support-gate.css"), "utf8");
|
const supportGateCss = readFileSync(resolve(supportGateDirectory, "support-gate.css"), "utf8");
|
||||||
const supportGateJavaScript = readFileSync(resolve(supportGateDirectory, "support-gate.js"), "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 clientHints = "Sec-CH-UA, Sec-CH-UA-Full-Version-List, Sec-CH-UA-Platform";
|
||||||
const contentSecurityPolicy = [
|
const contentSecurityPolicy = [
|
||||||
"default-src 'self'",
|
"default-src 'self'",
|
||||||
@@ -903,9 +907,15 @@ export async function createApp(options: CreateAppOptions = {}) {
|
|||||||
for (const route of ["/", "/app", "/app/*", "/admin", "/admin/*"]) {
|
for (const route of ["/", "/app", "/app/*", "/admin", "/admin/*"]) {
|
||||||
app.get(route, { schema: { hide: true } }, async (_request, reply) => {
|
app.get(route, { schema: { hide: true } }, async (_request, reply) => {
|
||||||
reply.type("text/html; charset=utf-8");
|
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) => {
|
app.get("/support-gate.css", { schema: { hide: true } }, async (_request, reply) => {
|
||||||
reply.type("text/css; charset=utf-8");
|
reply.type("text/css; charset=utf-8");
|
||||||
return supportGateCss;
|
return supportGateCss;
|
||||||
|
|||||||
Reference in New Issue
Block a user