|
@@ -54,8 +54,15 @@ app.use(session({
|
|
|
}));
|
|
|
|
|
|
// 登录状态全局判断
|
|
|
-const { stateChecking } = require('./modules/main/middleware/index');
|
|
|
-app.use(stateChecking);
|
|
|
+/* const { stateChecking } = require('./modules/main/middleware/index');
|
|
|
+app.use(stateChecking); */
|
|
|
+app.use(function (req, res, next) {
|
|
|
+ // 在内部在调用,而不直接在外部require后直接作为中间件回调函数app.use(stateChecking);的原因:
|
|
|
+ // 由于各模块的引用不全是require,有些是import,import是预编译的。外部引用中间件可能会造成一些引用丢失。如养护中:project_model.js中gljFacade.addMixRatioForNew会丢失
|
|
|
+ // 不用过分担心性能问题。require有cache机制
|
|
|
+ const { stateChecking } = require('./modules/main/middleware/index');
|
|
|
+ stateChecking(req, res, next);
|
|
|
+});
|
|
|
|
|
|
//加载路由文件
|
|
|
fileUtils.getGlobbedFiles('./modules/**/routes/*.js').forEach(function(modelPath) {
|