this morning awoke find nodejitsu spinning out following error:
warning: connection.session() memorystore not designed production environment, leak memory, , not scale past single process.
'well then!' thought myself - , off went find more suitable. settled on redis, , began implementing connect-redis
, node-redis
application.
however, following error continues surface after repeated attempts @ fix. error follows:
typeerror: cannot set property 'loggedin' of undefined @ /users/ryan/aggregus/server.js:300:25 @ promise.<anonymous> (/users/ryan/aggregus/object_models/user.js:60:5) @ promise.<anonymous> (/users/ryan/aggregus/node_modules/mongoose/node_modules/mpromise/lib/promise.js:162:8) @ promise.eventemitter.emit (events.js:95:17) @ promise.emit (/users/ryan/aggregus/node_modules/mongoose/node_modules/mpromise/lib/promise.js:79:38) @ promise.fulfill (/users/ryan/aggregus/node_modules/mongoose/node_modules/mpromise/lib/promise.js:92:20) @ /users/ryan/aggregus/node_modules/mongoose/lib/query.js:1813:13 @ model.document.init (/users/ryan/aggregus/node_modules/mongoose/lib/document.js:243:11) @ completeone (/users/ryan/aggregus/node_modules/mongoose/lib/query.js:1811:10) @ /users/ryan/aggregus/node_modules/mongoose/lib/query.js:1779:11
loggedin
referring req.session.loggedin
, session variable use track logged-in users. following application code in question:
var express = require('express'); var crypto = require('crypto'); var mongoose = require('mongoose'); var nodemailer = require('nodemailer'); var request = require('request'); var underscore = require('underscore'); var mandrill = require('node-mandrill')('0bfnpdenldiztu7axujdqq'); var connect = require('connect'); var engines = require('consolidate'); var fs = require('fs'); var redis = require("redis").createclient(); var redisstore = require('connect-redis')(express); var sessionstore = new redisstore({ client: redis }); var stripe_api_key = 'key'; var stripe = require('stripe')(stripe_api_key); var app = express(); app.configure(function() { app.engine('html', engines.jade); app.set('view engine', 'html'); app.use(express.cookieparser()); app.use(express.bodyparser()); app.use(express.session({secret: "svtabyrki4q786as37c785ta8vi56aiw4i8w467acv", store: sessionstore})); app.use(express.static(__dirname + '/www')); app.use(express.compress()); app.use(app.router); }); // mongoose connection var db = mongoose.connection; var dburi = 'hiddenurl'; db.on('disconnected', function() { mongoose.connect(dburi, {server:{auto_reconnect:true}}); }); db.on('error', function(error) { console.error('error in mongodb connection: ' + error); mongoose.disconnect(); }); mongoose.connect(dburi, {server:{auto_reconnect:true}}); // mongoose object models var user = require('./object_models/user')(mongoose, nodemailer, mandrill); var notifications = require('./object_models/notification')(mongoose, nodemailer); var experience = require('./object_models/experience')(mongoose, nodemailer); var booking = require('./object_models/booking')(mongoose, nodemailer); var review = require('./object_models/review')(mongoose, nodemailer); var heart = require('./object_models/heart')(mongoose, nodemailer); var message = require('./object_models/message')(mongoose, nodemailer); // nodemailer settings var smtptransport = nodemailer.createtransport("smtp",{ service: "gmail", auth: { user: "ryan@aggregus.com", pass: pwd } }); // bootstrap call app.get('/', function(req, res) { res.render('../index.html'); console.log("wusup"); });
to provide further clarity, here have tried until point no avail:
- i have placed
app.use(express.cookieparser());
priorexpress.session
call, articles of subject suggested. - i have ensured
new redisstore
call referencesclient
directly upon initialization. - i have placed
app.use(app.router)
after both init calls bothexpress.session
, 'express.cookieparser'. - my redis server functional, via
createclient()
call.
this similar question resolved preventing rather insignificant app.use
initialization call app.router
prior express' sessionstore being initialized.
thus, tl;dr: in using connect-redis
, session variables return undefined
. have scoured web answers, , clue app.router
being started prior express' own session handling. little glitch occurs beyond me. gods of stack overflow have mercy on poor soul.
edit: thought package.json might handy reference. generated via nodejitsu:
{ "name": "aggregus", "subdomain": "aggregus-aggregus", "scripts": { "start": "node server.js" }, "version": "0.0.0-14", "engines": { "node": "0.8.x" }, "dependencies": { "connect": "2.7.8", "consolidate": "0.9.1", "express": "3.2.2", "jade": "0.30.0", "mongoose": "3.6.9", "node-mandrill":"1.0.1", "nodemailer": "0.4.1", "request":"2.22.0", "stripe": "1.3.0", "underscore":"1.4.4" } }
you're calling connect-redis wrong, , don't need redis installed separately. however, don't see connect-redis in package.json, should npm install --save connect-redis
. this:
var express = require('express'); var redisstore = require('connect-redis')(express); var ports = require('./classes/ports.js'); var config = require('./config/config.js'); var routes = require('./routes'); var errors = require('./classes/errors.js'); var app = express(); ports(app); app .use(express.logger()) .use(express.compress()) .use(express.cookieparser()) .use(express.session({ store: new redisstore({ port: config.redisport, host: config.redishost, db: config.redisdatabase, pass: config.redispassword }), secret: 'your secret here', proxy: true, cookie: { secure: true } })) .use(express.favicon(__dirname + '/../public/img/favicon.ico')) .use(express.bodyparser()) .use(express.methodoverride()) routes(app); errors(app);
Comments
Post a Comment