Created
November 11, 2012 19:38
-
-
Save anonymous/4056016 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
app.configure(function(){ | |
app.use(function (req, res, next) { res.locals.session = req.session; next();}); | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'ejs'); | |
//app.use(express.logger()); | |
app.use(express.cookieParser()); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(express.session({ secret: 'keyboard cat' })); | |
app.use(passport.initialize()); | |
app.use(passport.session()); | |
app.use(app.router); | |
app.use(express.static(__dirname + '/public')); | |
app.use(function(req, res, next){ | |
res.status(404); | |
// respond with html page | |
if (req.accepts('html')) { | |
res.render('errors/404', { url: req.url, user : null }); | |
return; | |
} | |
// respond with json | |
if (req.accepts('json')) { | |
res.send({ error: 'Not found' }); | |
return; | |
} | |
// default to plain-text. send() | |
res.type('txt').send('Not found'); | |
}); | |
//this is the last use()d middleware, so we're assuming it's some sort of an error | |
app.use(function(err, req, res, next) { | |
var status = err.status || 500; | |
// if (err instanceof MongoError) return res.render('/error/500', {err}) | |
switch (status) { | |
case 400: | |
return res.render('errors/400', {error : err, status: status} ); | |
case 404: | |
return res.render('errors/404', { status: 404, url: req.url }); | |
case 500: | |
return res.render('errors/500', {error : err, user: null}); | |
} | |
//if (err instanceof MongoError) return res.send(503, 'service unavailable') | |
//log.error(err, { url: req.url}); | |
return res.send(err.stack); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment