合入主线登录和营业时段策略,对齐旧界面与 React 访问流程

This commit is contained in:
黄健铭 committed 2026-12-05 21:46:55 -08:00
commit 42395de23a
113 files changed
+1915 -558

No files matched your search

+9 -3
View File
@@ -4,6 +4,7 @@
// 路径解码后必须仍落在 web/dist 之内,否则按未知地址 404。
const fs = require('node:fs');
const path = require('node:path');
const { send, HTML } = require('../http');
const { fail } = require('../../core/ledger');
const DIST_DIR = path.join(__dirname, '..', '..', 'web', 'dist');
const TYPES = {
@@ -37,8 +38,7 @@ function readFile(file) {
return null;
}
}
function serveWebNext(res, pathname, isPost, { distDir = DIST_DIR } = {}) {
if (isPost) fail('地址不存在', 404);
function nextFile(pathname, distDir = DIST_DIR) {
let relative;
try {
relative = decodeURIComponent(pathname.slice('/next'.length));
@@ -52,11 +52,17 @@ function serveWebNext(res, pathname, isPost, { distDir = DIST_DIR } = {}) {
const last = relative.split('/').pop();
const asset = last.includes('.');
const file = asset ? target : path.join(root, 'index.html');
return file;
}
function serveWebNext(res, pathname, isPost, { distDir = DIST_DIR } = {}) {
if (isPost) fail('地址不存在', 404);
const file = nextFile(pathname, distDir);
const type = TYPES[path.extname(file).toLowerCase()];
const body = type ? readFile(file) : null;
if (!body) fail('地址不存在', 404);
if (type === HTML) return send(res, 200, body, type);
// 直接写出原始字节:通用 send() 会把 JSON 类型的内容再序列化一次。
res.writeHead(200, { 'Content-Type': type });
res.end(body);
}
module.exports = { serveWebNext, webNextEnabled, isNextPath, DIST_DIR };
module.exports = { serveWebNext, webNextEnabled, isNextPath, nextFile, DIST_DIR };