fix(POSTV1-02): 修复便携版网页入口门禁
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
-3
@@ -238,6 +238,7 @@ export interface CreateAppOptions {
|
||||
assetReleases?: AssetReleaseReader;
|
||||
bootstrap?: () => BootstrapResponse | Promise<BootstrapResponse>;
|
||||
browserGate?: boolean;
|
||||
productIndexHtml?: string;
|
||||
browserSupportRelease?: BrowserSupportRelease;
|
||||
browserSupportSecret?: Buffer;
|
||||
credits?: CreditService;
|
||||
@@ -273,7 +274,7 @@ const supportGateHtml = readFileSync(resolve(supportGateDirectory, "index.html")
|
||||
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"))
|
||||
const packagedProductIndexHtml = 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";
|
||||
@@ -714,6 +715,7 @@ export async function createApp(options: CreateAppOptions = {}) {
|
||||
)
|
||||
: undefined);
|
||||
const browserGate = options.browserGate ?? true;
|
||||
const productIndexHtml = options.productIndexHtml ?? packagedProductIndexHtml;
|
||||
const browserSupportSecret = options.browserSupportSecret ?? randomBytes(32);
|
||||
const browserSupportRelease = options.browserSupportRelease;
|
||||
const app = Fastify({
|
||||
@@ -905,9 +907,16 @@ export async function createApp(options: CreateAppOptions = {}) {
|
||||
});
|
||||
|
||||
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");
|
||||
return productIndexHtml ?? supportGateHtml;
|
||||
if (!browserGate) return productIndexHtml ?? supportGateHtml;
|
||||
const verified = verifyBrowserSupportCookie({
|
||||
cookieHeader: headerValue(request.headers.cookie),
|
||||
release: browserSupportRelease,
|
||||
secChUa: headerValue(request.headers["sec-ch-ua"]),
|
||||
secret: browserSupportSecret,
|
||||
});
|
||||
return verified.supported && productIndexHtml ? productIndexHtml : supportGateHtml;
|
||||
});
|
||||
}
|
||||
app.get("/assets/*", { schema: { hide: true } }, async (request, reply) => {
|
||||
|
||||
Reference in New Issue
Block a user