【问题标题】:restify with connect redis session doesnt handle uncaughtException exception (server shuts down)restify with connect redis session 不处理 uncaughtException 异常(服务器关闭)
【发布时间】:2023-03-25 03:46:02
【问题描述】:

我正在使用节点 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);
});

【问题讨论】:

    标签: session exception connect restify node-redis


    【解决方案1】:

    我在上面运行了你的代码,我的浏览器输出了下面的内容,服务器仍然在运行:

    {"code":"InternalError","message":"Internal server error"}
    

    也许您使用的是旧版本的节点?您是否为每个必需项目正确运行“npm install”?提供更多信息,我们可以提供更多帮助!

    【讨论】:

      猜你喜欢
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      相关资源
      最近更新 更多