Files
weiguang-jewelry-ledger/新账系统/server/middleware/static.js
T
黄健铭andClaude Opus 5.5 9ec37196d4 目录重组:后端按core/domains分领域存放(仅移动与更新引用)
- 50个后端模块用git mv移入core/与domains/<领域>/,入口server.js、launch.js、restore.js及server/原位不动
- 所有require路径由脚本按新旧位置统一换算(后端、server/、测试)
- 新增test/app-paths.test.js,锁定默认数据目录、public目录与飞书配置文件的绝对位置
- 维护与部署.md补充目录说明并更新模块路径

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 13:01:19 -08:00

56 lines
2.2 KiB
JavaScript

'use strict';
const fs = require('node:fs');
const path = require('node:path');
const { fail } = require('../../core/ledger');
const { send } = require('../http');
const PUBLIC_DIR = path.join(__dirname, '..', '..', 'public');
const ASSETS = {
'/': 'index.html',
'/private-operations-ui.js': 'private-operations-ui.js',
'/app.js': 'app.js',
'/order-copy.js': 'order-copy.js',
'/order-templates.js': 'order-templates.js',
'/order-templates-ui.js': 'order-templates-ui.js',
'/order-edit-ui.js': 'order-edit-ui.js',
'/order-cancellations-ui.js': 'order-cancellations-ui.js',
'/order-changes-ui.js': 'order-changes-ui.js',
'/order-after-sales-ui.js': 'order-after-sales-ui.js',
'/order-ownership-ui.js': 'order-ownership-ui.js',
'/daily-funds-ui.js': 'daily-funds-ui.js',
'/team-funds-ui.js': 'team-funds-ui.js',
'/cost-funding-ui.js': 'cost-funding-ui.js',
'/price-locks-ui.js': 'price-locks-ui.js',
'/price-lock-changes-ui.js': 'price-lock-changes-ui.js',
'/material-pools-ui.js': 'material-pools-ui.js',
'/recoveries-ui.js': 'recoveries-ui.js',
'/recovery-changes-ui.js': 'recovery-changes-ui.js',
'/inventory-changes-ui.js': 'inventory-changes-ui.js',
'/pockets-ui.js': 'pockets-ui.js',
'/shop-settings-ui.js': 'shop-settings-ui.js',
'/employees-ui.js': 'employees-ui.js',
'/credit-card-fees.js': 'credit-card-fees.js',
'/calculations.js': 'calculations.js',
'/order-formula.js': 'order-formula.js',
'/fee-estimates.js': 'fee-estimates.js',
'/order-cost-presets-ui.js': 'order-cost-presets-ui.js',
'/app.css': 'app.css',
'/print.js': 'print.js',
};
// 白名单静态文件;其余(含任何 POST)一律 404。
function serveStatic(res, route, isPost) {
// 只查自有属性,/constructor、/__proto__ 等不能命中原型。
const file = Object.hasOwn(ASSETS, route) ? ASSETS[route] : undefined;
if (!file || isPost) fail('地址不存在', 404);
send(
res,
200,
fs.readFileSync(path.join(PUBLIC_DIR, file)),
file.endsWith('.js')
? 'application/javascript; charset=utf-8'
: file.endsWith('.css')
? 'text/css; charset=utf-8'
: 'text/html; charset=utf-8',
);
}
module.exports = { serveStatic, ASSETS };