1
This commit is contained in:
56
app.js
56
app.js
@@ -1,62 +1,36 @@
|
||||
/**
|
||||
* 后端应用入口(模板项目)
|
||||
* 使用 node-core-framework 框架
|
||||
* 后端应用入口 — node-core-framework(约定见 .cursor/rules/node-core-framework.mdc)
|
||||
*/
|
||||
|
||||
const Framework = require('./framework/node-core-framework.js');
|
||||
const config = require('./config/framework.config.js');
|
||||
const businessAssociations = require('./config/model.associations.js');
|
||||
|
||||
|
||||
// 定时任务(在 Framework 初始化后再加载)
|
||||
|
||||
|
||||
const Framework = require("./framework/node-core-framework.js");
|
||||
const config = require("./config/framework.config.js");
|
||||
const businessAssociations = require("./config/model.associations.js");
|
||||
|
||||
async function start() {
|
||||
try {
|
||||
console.log('🚀 正在启动应用...\n');
|
||||
console.log('⚙️ 正在初始化框架...');
|
||||
|
||||
|
||||
|
||||
console.log("🚀 正在启动应用...\n");
|
||||
console.log("⚙️ 正在初始化框架...");
|
||||
|
||||
const framework = await Framework.init({
|
||||
...config,
|
||||
businessAssociations,
|
||||
beforeInitApi: async (framework) => {
|
||||
const { buildProxyRoutes } = require('./api/controller_custom/proxy_api');
|
||||
// 从 swagger.json 动态注册 193 个转发路由到 /api 前缀
|
||||
const proxyRoutes = buildProxyRoutes();
|
||||
const n = Object.keys(proxyRoutes).length;
|
||||
// 与 swagger 文档一致:/admin/...、/login/...
|
||||
framework.addRoutes("", proxyRoutes);
|
||||
// 兼容历史调用:/api/admin/...
|
||||
framework.addRoutes("/api", proxyRoutes);
|
||||
console.log(`📡 已注册 ${n} 个转发接口(文档路径 + /api 前缀各一套)`);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
await framework.start(config.port.node);
|
||||
const schedule = require('./middleware/schedule.js');
|
||||
// if (config.env !== 'development') {
|
||||
await schedule.init();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
const schedule = require("./middleware/schedule.js");
|
||||
await schedule.init();
|
||||
|
||||
console.log(`\n📚 API 文档: http://localhost:${config.port.node}/api/docs`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n' + '='.repeat(60));
|
||||
console.error('❌ 应用启动失败!');
|
||||
console.error('='.repeat(60));
|
||||
console.error('错误信息:', error.message);
|
||||
console.error('错误堆栈:', error.stack);
|
||||
console.error('='.repeat(60) + '\n');
|
||||
console.error("\n" + "=".repeat(60));
|
||||
console.error("❌ 应用启动失败!");
|
||||
console.error("=".repeat(60));
|
||||
console.error("错误信息:", error.message);
|
||||
console.error("错误堆栈:", error.stack);
|
||||
console.error("=".repeat(60) + "\n");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
start();
|
||||
start();
|
||||
|
||||
Reference in New Issue
Block a user