Files
ClassHelper/website/serve.mjs
T
LoveChengke 82c85b59c1 feat(dist,deploy,website): 交付产物统一归集到 releases/<组件>/<版本>,补齐官网与 Linux 验收
三个打包脚本原先各写各的输出目录,现在一律直接落在仓库根 releases/<组件>/<版本>/,分层固定为安装包/免安装/构建中间;dist-win 用 --config.directories.output 覆盖 electron-builder 的目录后再整理,显式传入时不覆盖。插件侧顺手修掉一个既有 bug:原先 rmSync 整个组件目录,重打一次就把上一版的留档抹掉,现在只清当前版本目录。verify-packaged 的 --exe 默认值跟着改到新落点。

deploy/verify-linux.sh 修掉管道在 pipefail 下的 SIGPIPE 误判(命中被算成失败);CI workflow 的出包与上传路径同步;electron-builder.yml 显式指定安装包图标。

website/ 是产品官网(纯静态、无构建步骤,不进 pnpm workspace),含 beUI 动效 token 与实机留档图;客户端冒烟相应加了采集留档图用的外观开关。
2026-10-06 15:31:38 +08:00

57 lines
1.9 KiB
JavaScript

/**
* 官网本地预览用的最小静态服务器 —— 只是为了 `node serve.mjs` 能直接看页面。
* 正式发布时把 website/ 整个目录丢给任意静态托管 / Nginx 即可,不需要这个文件。
*
* node website/serve.mjs → http://127.0.0.1:5180
* PORT=8080 node website/serve.mjs
*/
import { createServer } from 'node:http';
import { readFile, stat } from 'node:fs/promises';
import { extname, join, normalize, resolve, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
const ROOT = resolve(fileURLToPath(new URL('.', import.meta.url)));
const PORT = Number(process.env.PORT ?? 5180);
const MIME = {
'.html': 'text/html; charset=utf-8',
'.css': 'text/css; charset=utf-8',
'.js': 'text/javascript; charset=utf-8',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
'.webmanifest': 'application/manifest+json',
'.woff2': 'font/woff2',
};
const server = createServer(async (request, response) => {
const url = new URL(request.url ?? '/', 'http://localhost');
const requested = decodeURIComponent(url.pathname);
const target = normalize(join(ROOT, requested === '/' ? 'index.html' : requested));
// 目录穿越防护:解析结果必须仍在 ROOT 里
if (target !== ROOT && !target.startsWith(ROOT + sep)) {
response.writeHead(403).end('Forbidden');
return;
}
try {
const info = await stat(target);
const file = info.isDirectory() ? join(target, 'index.html') : target;
const body = await readFile(file);
response.writeHead(200, {
'content-type': MIME[extname(file)] ?? 'application/octet-stream',
'cache-control': 'no-store',
});
response.end(body);
} catch {
response.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' }).end('404');
}
});
server.listen(PORT, '127.0.0.1', () => {
console.log(`官网预览:http://127.0.0.1:${PORT}`);
});