Files
weiguang-jewelry-ledger/新账系统/server/middleware/static.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
2.3 KiB
JavaScript
Raw Normal View History

'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',
'/ledger-values.js': 'ledger-values.js',
'/report-rules.js': 'report-rules.js',
'/recovery-rules.js': 'recovery-rules.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) {
2026-12-04 12:46:24 -08:00
// 只查自有属性,/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 };