S
S
Stopy2015-08-21 13:50:30
Node.js
Stopy, 2015-08-21 13:50:30

How to enable Redis cookies?

Standard connection cookies work, but if I write a store for cookies / sessions, then when I access req.session, it says that req.session is undefined

app.use(session({
  secret: 'secretString',
  cookie: { maxAge: 3600000 * 12 , httpOnly: true},
  resave: true,
  saveUninitialized: false,
  store: new RedisStore()
}));

Here is the server code:
var express = require('express');
var app = express();
var MongoClient = require('mongodb').MongoClient;

var path = require('path');
var favicon = require('serve-favicon');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
// var logger = require('morgan');
// var log = require('logger')(module);
var config = require('config');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
  secret: 'secretString',
  cookie: { maxAge: 3600000 * 12 , httpOnly: true},
  resave: true,
  saveUninitialized: false,
  store: new RedisStore()
}));
app.use("/", express.static(__dirname + '/public'));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pomeo, 2015-08-21
@Stopy

So everything seems to be fine, add host for the radish

new RedisStore({
    host:'127.0.0.1',
    port:6379
  })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question