refactor: 统一ID生成方式,使用新的idGenerator模块 refactor: 重构模型ID生成逻辑,允许空ID并在创建前自动生成 fix(roomSchema): 使机房ID字段变为可选并更新前端表单验证 style: 格式化代码并优化导入语句 test: 添加操作日志集成测试文件 docs: 添加错误处理模块文档
26 lines
771 B
JavaScript
26 lines
771 B
JavaScript
const path = require('path');
|
|
const routesConfig = require('../config/routes');
|
|
|
|
function loadRoutes(app) {
|
|
const routesDir = path.join(__dirname, '../routes');
|
|
|
|
routesConfig.forEach(routeConfig => {
|
|
try {
|
|
const routerPath = path.join(routesDir, routeConfig.file);
|
|
const router = require(routerPath);
|
|
|
|
if (typeof router === 'function') {
|
|
app.use(routeConfig.path, router);
|
|
console.log(`路由已加载: ${routeConfig.path} -> ${routeConfig.file}`);
|
|
} else {
|
|
console.warn(`警告: ${routeConfig.file} 没有导出有效的 Express 路由器`);
|
|
}
|
|
} catch (error) {
|
|
console.error(`加载路由失败: ${routeConfig.file}`, error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = loadRoutes;
|