【发布时间】:2016-01-20 19:14:30
【问题描述】:
好的,我现在遇到的问题是我的错误处理程序在我当前使用的函数完成之前被调用:
function loadRoutes(route_path) {
fs.readdir(route_path, function(err, files) {
files.forEach(function (file) {
var filepath = route_path + '/' + file;
fs.stat(filepath, function (err, stat) {
if (stat.isDirectory()) {
loadRoutes(filepath);
} else {
console.info('Loading route: ' + file);
require(filepath)(app);
}
});
});
});
}
setTimeout(function() {
require('./errorhandle');
}, 10);
超时解决方案有效,但不是正确的解决方案。如果路由加载时间超过 10 毫秒,它将再次中断。 (404 阻止所有在它之前加载的页面)
【问题讨论】:
标签: node.js express routes http-status-code-404 fs