路由表化:新增路由匹配器、中间件与表驱动分发,迁移店铺设置/员工/货盘路由
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b9cb825be
commit
e082069f55
14 files changed
+525
-197
No files matched your search
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { fail } = require('../../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) {
|
||||
const file = ASSETS[route];
|
||||
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 };
|
||||
Reference in new issue
Block a user