我正在使用节点 restify 连接 redis 会话设置。我正在通过 restify 的 'uncaughtException' 事件处理未捕获的异常。但是,当我使用 connect redis 时,未捕获到 uncaughtExceptions 并且服务器关闭。
如何重现:运行以下代码,然后在浏览器上导航到 localhost:8000/api/boom
var connect = require('connect');
var restify = require('restify');
var bunyan = require('bunyan');
var RedisStore = require('connect-redis')(connect);
var app = restify.createServer({
log : bunyan.createLogger({name: "server"}),
});
var log = bunyan.createLogger({name: "app"});
app.on('uncaughtException', function(request, response, route, error) {
log.error(error);
response.send(new restify.InternalError("Internal server error"));
});
// please see
/*http://stackoverflow.com/questions/19409441/req-originalurl-not-set-by-restify-it-is-needed-by-connect-session-middleware/*/
app.use(function(req, res, next) {
req.originalUrl = req.url;
next();
});
app.use(connect.cookieParser());
app.use(connect.session({
secret : "open sesame",
store: new RedisStore({
"host": "127.0.0.1",
"pass": "",
"port": 6379
})
}));
//app.use(connect.static(__dirname + '/public'));
app.get('/api/boom', function(req, res, next) {
throw new Error("Boom!");
res.send("ok");
next();
});
(app).listen(8000, function() {
console.log("server started. Listening at " + 8000);
});