Node js, no response received when using connect-memcached

Hi, I am using compound and connect-memcached. Below is the content of my envirionment.js file:

module.exports = function (compound) { var express = require('express'); var MemcachedStore = require('connect-memcached')(express); var app = compound.app; require('./mongoose').init(compound); app.configure(function(){ app.use(compound.assetsCompiler.init()); app.use(express.static(app.root + '/public', { maxAge: 86400000 })); app.set('view engine', 'ejs'); app.set('view options', { complexNames: true }); app.set('jsDirectory', '/javascripts/'); app.set('cssDirectory', '/stylesheets/'); app.set('cssEngine', 'stylus'); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.favicon()); app.use(express.logger()); app.use(express.cookieParser()); app.use(express.session({secret: 'AuthenticationSecret', store: new MemcachedStore})); app.use(app.router); }); }; 

When I start the server by providing the following command:

 NODE_ENV=production node . 

This starts fine, and I get:

 MemcachedStore initialized for servers: 127.0.0.1:11211 AssetsCompiler Precompiling assets: coffee, styl Compound server listening on 0.0.0.0:3000 within production environment 

When I request through the browser, I do not receive a response.

The following is the contents of the routes.js file:

 exports.routes = function (map) { map.get('api/yourname','names#index') } 

In my name controller:

 load('application'); action('index', function(req, res) { send({"name": "Senthil"}); }); 

PS: If I comment on the codes for using connect-memcached and the request through the browser, I get a response.

Thanks for your help in advance.

+6
source share
2 answers

Try adding brackets and configuration after new MemcacheStore so that it looks like this:

 app.use(express.session({ secret: 'AuthenticationSecret', store: new MemcachedStore({ hosts: [ '127.0.0.1:11212' ] }) })); 

(It is assumed that your memcache server is located in localhost: 11212 - if not, change the host string to the server host name or IP address.)

0
source

For sessions, you need a secret key. Otherwise, you will get this error.

Error: secret parameter required for sessions

I assume that you do not see the error because you are working in a production environment. Add secret key:

 app.use(express.session({ store: new MemcachedStore, secret: 'secret_key' })); 

Since you are using localhost, you do not need to specify a host or port.

0
source

All Articles