返回列表

转载: restify with connect redis session doesnt handle uncaughtException exception (server shuts down) #89

默认分类 2014/04/22 04:15

转载:https://github.com/visionmedia/connect-redis/issues/89

restify with connect redis session doesnt handle uncaughtException exception "Parameter 'url' must be a string, not undefined" (server shuts down) #89

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'));