Created
May 16, 2011 12:40
-
-
Save brianleroux/974379 to your computer and use it in GitHub Desktop.
ExpressJS so simple it should work but of course it does not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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...