6

Hi I'm using compoundjs and connect-memcached. Below is the content in 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 giving the following command:

NODE_ENV=production node .

It 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 via browser, I'm not getting any response.

Below is my routes.js file content:

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

In my names controller:

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

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

Thanks for your help in advance.

senthil
  • 1,307
  • 1
  • 11
  • 23

2 Answers2

0

Try adding parenthesis and a config after new MemcacheStore so that it looks like this:

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

(This is assuming your memcache server is at localhost:11212 - if not, then change the hosts line to your server's hostname or IP.)

Nathan Friedly
  • 7,837
  • 3
  • 42
  • 59
0

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

Error: secret option required for sessions

I'm assuming you don't see the error because you're running in the production environment. Add a secret key like this:

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

Since you're running localhost, you don't need to specify the host or port.

hexacyanide
  • 88,222
  • 31
  • 159
  • 162