我正在使用节点restify connect redis session setup。我正在通过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);
});
答案 0 :(得分:0)
我上面运行了你的代码,我的浏览器输出如下,服务器仍在运行:
{"code":"InternalError","message":"Internal server error"}
也许您正在使用旧版本的节点?您是否正确为每个必需项目运行“npm install”?提供更多信息,我们可以提供更多帮助!