Updated examples
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 75661a2 · Browse files · 4 files·+15 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+15 added−13 removed
- other:+15 added−13 removed
Provenance
- Commit
f60bcca- Tree
38fca9a- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
75661a2
4 files changed+15 added−13 removed
modified:examples/blog/blog/index.js+3 added-2 removed
33 unmodified lines343536373838394041414243444533 unmodified lines } });});
app.get('/post/:id', function(req, res, params){app.get('/post/:id', function(req, res){ var id = req.params.id; res.render('post', { locals: { post: posts[params.id] post: posts[id] } });});No newline at end of fileNo newline at end of filemodified:examples/error/app.js+1 added-1 removed
11 unmodified lines121314151616171819206 unmodified lines11 unmodified lines // Caught and passed down to the errorHandler middleware throw new Error('something broke!');});
app.get('/next', function(req, res, params, next){app.get('/next', function(req, res, next){ // We can also pass exceptions to next() next(new Error('oh no!'))});
6 unmodified linesmodified:examples/github/app.js+2 added-2 removed
77 unmodified lines78798081828382838485868729 unmodified lines77 unmodified lines/** * Display repos. */
app.get('/repos/*', function(req, res, params, next){ var names = params[0].split('/'),app.get('/repos/*', function(req, res, next){ var names = req.params[0].split('/'), users = []; (function fetchData(name){ // We have a user name if (name) {29 unmodified linesmodified:examples/resource/app.js+9 added-8 removed
9 unmodified lines10 // Ad-hoc example resource method11 12 app.resource = function(path, obj) {13 this.get(path, obj.index);14- this.get(path + '/:a..:b', function(req, res, params){15- var a = parseInt(params.a, 10),16- b = parseInt(params.b, 10);14+ this.get(path + '/:a..:b', function(req, res){15+ var a = parseInt(req.params.a, 10),16+ b = parseInt(req.params.b, 10);17 obj.range(req, res, a, b);18 });19 this.get(path + '/:id', obj.show);20 this.del(path + '/:id', obj.destroy);15 unmodified lines36 var User = {37 index: function(req, res){38 res.send(users);39 },40- show: function(req, res, params){41- res.send(users[params.id] || { error: 'Cannot find user' });40+ show: function(req, res){41+ res.send(users[req.params.id] || { error: 'Cannot find user' });42 },43- destroy: function(req, res, params){44- var destroyed = params.id in users;45- delete users[params.id];43+ destroy: function(req, res){44+ var id = req.params.id;45+ var destroyed = id in users;46+ delete users[id];47 res.send(destroyed ? 'destroyed' : 'Cannot find user');48 },49 range: function(req, res, a, b){50 res.send(users.slice(a, b));24 unmodified lines