v0.10.5 首页 H2 产品线入口 ×6:ImageBoxWidget 重构为 Elementor 忠实 DOM + slim 白名单补齐 + H2 scoped CSS(post-18 对齐,桌面/移动/hover 实测一致)

This commit is contained in:
BigCode
2026-11-01 00:15:29 +08:00
commit 5b83e71ad9
128 changed files with 20008 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
/**
* # 脚本 生产环境入口
* 包装 dist/server/server.js(TanStack Start 的 fetch handler):
* 先用 dist/client 的静态文件(构建产物 JS/CSS 等)直接应答,未命中的请求
* 交给 Start handler。没有这层包装时 /assets/* 会被路由 307 加尾斜杠后 404,
* 页面完全无 JS(水合不运行)。
*/
// 构建产物无类型声明(产物哈希文件名随构建变化)
// @ts-expect-error 构建产物无 d.ts
import serverEntry from "../dist/server/server.js";
import { readdirSync } from "node:fs";
/** # 成员变量 dist/client 静态文件表(pathname → 绝对路径,启动时递归扫描一次) **/
const CLIENT_DIR = new URL("../dist/client/", import.meta.url).pathname;
const staticFiles = new Map<string, string>();
/** # 函数 递归收集 dist/client 下全部静态文件 */
function walk(dir: string): void {
for (const e of readdirSync(dir, { withFileTypes: true })) {
const p = dir + "/" + e.name;
if (e.isDirectory()) walk(p);
// 归一化 key:物理路径去掉 CLIENT_DIR 前缀(可能残留多余斜杠)后补单斜杠
else staticFiles.set("/" + p.slice(CLIENT_DIR.length).replace(/^\/+/, ""), p);
}
}
walk(CLIENT_DIR);
export default {
/** # 成员变量 监听端口(PORT 环境变量可覆盖) **/
port: Number(process.env.PORT ?? 3312),
/** # 函数 请求入口:静态文件优先,其余交给 Start handler */
async fetch(req: Request): Promise<Response> {
const url = new URL(req.url);
const f = staticFiles.get(url.pathname);
if (f) {
return new Response(Bun.file(f), {
headers: { "cache-control": "public, max-age=31536000, immutable" },
});
}
return serverEntry.fetch(req);
},
};