Skip to content
Myr

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 file

Take 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 back
1
2/**3 * Module dependencies.4 */56var express = require('./../../lib/express');7

Fixed pages app exampleTj Holowaychukbefore adoption7e1b222

lines 8–9why, one step back
8var app = express.createServer(),
9 sys = require('sys');

Added test for multiple app.error() callsTj Holowaychukbefore adoption51611ec

lines 10–12why, one step back
10
11app.set('views', __dirname + '/views');12

Improved pages demoTj Holowaychukbefore adoption479f297

line 13why, one step back
13// Provide our app with the notion of NotFound exceptions

Added test for multiple app.error() callsTj Holowaychukbefore adoption51611ec

line 14why, one step back
14

Fixed pages app exampleTj Holowaychukbefore adoption7e1b222

lines 15–22why, one step back
15function NotFound(msg){
16 this.name = 'NotFound';17 Error.call(this, msg);18 Error.captureStackTrace(this, arguments.callee);19}2021sys.inherits(NotFound, Error);22

Improved pages demoTj Holowaychukbefore adoption479f297

lines 23–26why, one step back
23// 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.26

Merge branch 'fix-error'Tj Holowaychukbefore adoption498115d

lines 27–30why, one step back
27// These handlers could potentially be defined within
28// configure() blocks to provide introspection when29// in the development environment.30

Improved pages demoTj Holowaychukbefore adoption479f297

lines 31–41why, one step back
31app.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 like41

Removed connect.redirect()Tj Holowaychukbefore adoption0fce93b

line 42why, one step back
42app.error(function(err, req, res){

Improved pages demoTj Holowaychukbefore adoption479f297

line 43why, one step back
43 res.render('500.jade', {

Added test for multiple app.error() callsTj Holowaychukbefore adoption51611ec

lines 44–47why, one step back
44 locals: {
45 error: err46 } 47 });

Merge branch 'fix-error'Tj Holowaychukbefore adoption498115d

lines 48–61why, one step back
48});
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 back
62});
6364app.listen(3000);