Merge branch 'mvc'
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 · parents 35ca13b, 99f49f1 · Browse files · 3 files·+29 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+29 added−2 removed
- other:+29 added−2 removed
Provenance
- Commit
5add7cb- Tree
7261846- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent 1
35ca13b- Parent 2
99f49f1
3 files changed+29 added−2 removed
modified:examples/mvc/views/app/index.html+3 added-1 removed
123456778910<h1>Application Index</h1><p>Try visiting one of the following urls:</p><ul> <li><a href="/users">/users</a></li> <li><a href="/users/1">/users/1</a></li> <li><a href="/users/1.json">/users/1.json</a></li> <li><a href="/users/1/edit">/users/1/edit</a></li> <li><a href="/users/5">/users/5 (non existent)</a></li> <li><a href="/accounts">/accounts (404, non existent)</a></li> <li><a href="/users/1.foo">/users/1.foo (500, unsupported format)</a></li></ul>No newline at end of fileNo newline at end of fileadded:examples/mvc/views/500.html+2 added
12<h1>Internal Server Error</h1><p>Sorry an error has occurred, please try refreshing the page or navigate back to <a href="/">home</a>.</p>No newline at end of filemodified:examples/mvc/mvc.js+24 added-1 removed
20 unmodified lines212223242526272829303132333454 unmodified lines8990919287939495969717 unmodified lines1151161171181191201211221231241251261271281291301311321331341351361371381391401411429 unmodified lines20 unmodified lines app.use(express.session()); app.use(app.router); app.use(express.staticProvider(__dirname + '/public'));
// Example 500 page app.error(function(err, req, res){ console.dir(err) res.render('500'); });
// Example 404 page via simple Connect middleware app.use(function(req, res){ res.render('404'); });54 unmodified lines case 'index': app.get(prefix, fn); break; case 'show': app.get(prefix + '/:id', fn); app.get(prefix + '/:id.:format?', fn); break; case 'add': app.get(prefix + '/:id/add', fn); break;17 unmodified lines
function controllerAction(name, plural, action, fn) { return function(req, res, next){ var render = res.render, format = req.params.format, path = __dirname + '/views/' + name + '/' + action + '.html'; res.render = function(obj, options, fn){ res.render = render; // Template path if (typeof obj === 'string') { return res.render(obj, options, fn); }
// Format support if (action == 'show' && format) { if (format === 'json') { return res.send(obj); } else { throw new Error('unsupported format "' + format + '"'); } }
// Render template res.render = render; options = options || {}; options.locals = options.locals || {}; // Expose obj as the "users" or "user" local if (action == 'index') {9 unmodified lines