Wednesday, 15 January 2014

node.js - Node + Redis not quite working -



node.js - Node + Redis not quite working -

i have initialisation code;

app.use(cookieparser); var redis = require('redis'); var redisoptions = {} redisoptions.client = redis.createclient(<removed>, 'pub-redis-12124.us-east-1-2.3.ec2.garantiadata.com'); app.use(session({ store: new redisstore(redisoptions), secret: 'keyboard cat', resave: true, saveuninitialized: true }));

in routing, have this;

router.post('/login', function (req, res) { var users = req.db.get('users'); users.findone({email: req.body.email}, function (err, user) { console.log(user); if (req.body.password == user.password) { req.session.id = user._id; console.log("id:" ); res.send('successful login' + req.session.id); } else { // create sure log failed auth requests var log = req.db.get('failed_auth'); var fail_info = {}; fail_info.email = req.body.email; fail_info.ip = req.headers['x-forwarded-for'] || req.connection.remoteaddress; fail_info.timestamp = date.now(); log.insert(fail_info, function(doc) { res.send('bad creds'); }); } }); });

however when seek go through code, error;

typeerror: cannot set property 'id' of undefined

my redis server 1 of free hosted ones redislabs. i'm not sure if need authenticate although don't think do. tips on way forward?

edit:

var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var bodyparser = require('body-parser') var cookieparser = require('cookie-parser')(); var session=require('express-session'); var redisstore = require('connect-redis')(session); // new code var monk = require('monk'); var db = monk('localhost:27017/manpoints'); var routes = require('./routes/index'); var business relationship = require('./routes/account') var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // uncomment after placing favicon in /public //app.use(favicon(__dirname + '/public/favicon.ico')); app.use(logger('dev')); app.use(bodyparser.json());

ignore mess/unused stuff, i've been trying lots of different things trying work.

node.js express redis

No comments:

Post a Comment