Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created May 16, 2011 12:40
Show Gist options
  • Save brianleroux/974379 to your computer and use it in GitHub Desktop.
Save brianleroux/974379 to your computer and use it in GitHub Desktop.
ExpressJS so simple it should work but of course it does not.
require.paths.unshift('./node_modules')
var express = require('express')
, app = express.createServer()
, store = require('connect-redis')
app.configure(function(){
app.use(express.methodOverride())
app.use(express.bodyParser())
app.use(app.router)
app.use(express.cookieParser())
app.use(express.session({ secret:'none', store: new store}))
})
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }))
app.use(express.logger())
})
app.configure('production', function(){
app.use(express.errorHandler());
})
exports.app = app
var app = require('./config').app
, port = process.env.PORT || 4000
app.get('/', function (req, res) {
console.log(req.session) // undefined
res.render('index.html.ejs', {req: req})
})
app.listen(port)
console.log('Listening on port ' + port)
@tj
Copy link

tj commented May 16, 2011

your middleware config makes no sense.. having methodOverride above bodyParser also makes no sense.. it needs req.body to check for req.body._method, and both cookieParser/session should be above app.router. also having logger() at the bottom will not work (typically it's at the top) because it wraps res.end() to provide response time data...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment