prepping blog example for new express
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 f84ec80 · Browse files · 3 files·+35 added−18 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+35 added−18 removed
- other:+35 added−18 removed
Provenance
- Commit
05b76a1- Tree
503464c- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
f84ec80
3 files changed+35 added−18 removed
added:examples/blog/middleware/locals.js+31 added
12345678910111213141516171819202122232425262728293031
/** * Module dependencies. */
var messages = require('express-messages');
module.exports = function(req, res, next){ // access the app without passing it into // this file explicitly var app = req.app;
// express-messages returns a function which // when called will flush the session-based // notification messages as HTML. Because of // this "flushing" action it must be a function // otherwise any view render would remove the // notifications regardless of their delay. res.locals.messages = messages(req, res);
// expose the app's mount-point // so that urls can adjust. For example // if you run this example /post/add works // however if you run the mounting example // it adjusts to /blog/post/add res.locals.base = '/' == app.route ? '' : app.route;
// all we wanted to do was assign some view locals // so pass control to the next middleware next();};No newline at end of filemodified:examples/blog/app.js+3 added-17 removed
12345676789106 unmodified lines17181920222324252627282930313233343536212223242526272829303132333410 unmodified lines
/** * Module dependencies. */
var express = require('../../lib/express') , messages = require('express-messages');var express = require('../../lib/express');
var app = module.exports = express.createServer();
// Config6 unmodified linesapp.mounted(function(other){ console.log('ive been mounted!');});
// Flash message helper provided by express-messages// $ npm install express-messages
app.dynamicHelpers({ messages: messages , base: function(){ // return the app's mount-point // so that urls can adjust. For example // if you run this example /post/add works // however if you run the mounting example // it adjusts to /blog/post/add return '/' == app.route ? '' : app.route; }});
// Middleware
app.configure(function(){ app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser()); app.use(express.session({ secret: 'keyboard cat' })); app.use(require('./middleware/locals')); app.use(messages()); app.use(app.router); app.use(express.static(__dirname + '/public')); app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));});10 unmodified linesmodified:Readme.md+1 added-1 removed
102 unmodified lines103 ## Viewing Examples104 105 First install the dev dependencies to install all the example / test suite deps:106 107- $ npm install107+ $ npm install -d108 109 then run whichever tests you want:110 111 $ node examples/jade/app.js35 unmodified lines