app.js
This file
Path
examples/pages/app.js
64 lines · 1.3 KiB · JavaScript
Last changed by
Merge branch 'fix-error'Tj Holowaychukbefore adoption498115d
History of this fileTake it
The walk stopped after 200 commits: lines older than 51611ec point at it.
Added test for multiple app.error() callsTj Holowaychukbefore adoption51611ec
lines 1–7why, one step back12/**3 * Module dependencies.4 */56var express = require('./../../lib/express');7Fixed pages app exampleTj Holowaychukbefore adoption7e1b222
lines 8–9why, one step back8var app = express.createServer(),9 sys = require('sys');Added test for multiple app.error() callsTj Holowaychukbefore adoption51611ec
lines 10–12why, one step back1011app.set('views', __dirname + '/views');12Improved pages demoTj Holowaychukbefore adoption479f297
line 13why, one step back13// Provide our app with the notion of NotFound exceptionsAdded test for multiple app.error() callsTj Holowaychukbefore adoption51611ec
line 14why, one step back14Fixed pages app exampleTj Holowaychukbefore adoption7e1b222
lines 15–22why, one step back15function NotFound(msg){16 this.name = 'NotFound';17 Error.call(this, msg);18 Error.captureStackTrace(this, arguments.callee);19}2021sys.inherits(NotFound, Error);22Improved pages demoTj Holowaychukbefore adoption479f297
lines 23–26why, one step back23// We can call app.error() several times as shown below.24// Here we check for an instanceof NotFound and show the25// 404 page, or we pass on to the next error handler.26Merge branch 'fix-error'Tj Holowaychukbefore adoption498115d
lines 27–30why, one step back27// These handlers could potentially be defined within28// configure() blocks to provide introspection when29// in the development environment.30Improved pages demoTj Holowaychukbefore adoption479f297
lines 31–41why, one step back31app.error(function(err, req, res, next){32 if (err instanceof NotFound) {33 res.render('404.jade');34 } else {35 next(err);36 }37});3839// Here we assume all errors as 500 for the simplicity of40// this demo, however you can choose whatever you like41Removed connect.redirect()Tj Holowaychukbefore adoption0fce93b
line 42why, one step back42app.error(function(err, req, res){Improved pages demoTj Holowaychukbefore adoption479f297
line 43why, one step back43 res.render('500.jade', {Added test for multiple app.error() callsTj Holowaychukbefore adoption51611ec
lines 44–47why, one step back44 locals: {45 error: err46 } 47 });Merge branch 'fix-error'Tj Holowaychukbefore adoption498115d
lines 48–61why, one step back48});4950// Routes5152app.get('/', function(req, res){53 res.render('index.jade');54});5556app.get('/404', function(req, res){57 throw new NotFound;58});5960app.get('/500', function(req, res){61 throw new Error('keyboard cat!');Added test for multiple app.error() callsTj Holowaychukbefore adoption51611ec
lines 62–64why, one step back62});6364app.listen(3000);