Regenerated guide
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 4bc8a86 · Browse files · 2 files·+65 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+65 added−0 removed
- other:+65 added−0 removed
Provenance
- Commit
f179979- Tree
f7550b9- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
4bc8a86
2 files changed+65 added−0 removed
modified:docs/guide.1+37 added
775 unmodified lines776 .fi777 .778 .IP "" 0779 .780+.P781+Now the \fIreq\.session\fR and \fIreq\.sessionStore\fR properties will be accessible to all routes and subsequent middleware\. Properties on \fIreq\.session\fR are automatically saved on a response, so for example if we wish to shopping cart data:782+.783+.IP "" 4784+.785+.nf786+787+var RedisStore = require(\'connect\-redis\');788+app\.use(express\.cookieDecoder());789+app\.use(express\.session({ store: new RedisStore }));790+app\.use(express\.bodyDecoder());791+792+app\.post(\'/add\-to\-cart\', function(req, res){793+ // Perhaps we posted several items with a form794+ // (use the bodyDecoder() middleware for this)795+ var items = req\.body\.items;796+ req\.session\.items = items;797+ res\.redirect(\'back\');798+});799+800+app\.get(\'/add\-to\-cart\', function(req, res){801+ // When redirected back to GET /add\-to\-cart802+ // we could check req\.session\.items && req\.session\.items\.length803+ // to print out a message804+ if (req\.session\.items && req\.session\.items\.length) {805+ req\.flash(\'info\', \'You have %s items in your cart\', req\.session\.items\.length);806+ }807+ res\.render(\'shopping\-cart\');808+});809+.810+.fi811+.812+.IP "" 0813+.814+.P815+The \fIreq\.session\fR object also has methods such as \fISession#touch()\fR, \fISession#destroy()\fR, \fISession#regenerate()\fR among others to maintain and manipulate sessions\. For more information view the Connect Session \fIhttp://senchalabs\.github\.com/connect/session\.html\fR documentation\.816+.817 .SS "req\.header(key[, defaultValue])"818 Get the case\-insensitive request header \fIkey\fR, with optional \fIdefaultValue\fR:819 .820 .IP "" 4711 unmodified linesmodified:docs/guide.html+28 added
702 unmodified lines703 app.use(express.cookieDecoder());704 app.use(express.session({ store: new RedisStore }));705 </code></pre>706 707+<p>Now the <em>req.session</em> and <em>req.sessionStore</em> properties will be accessible to all routes and subsequent middleware. Properties on <em>req.session</em> are automatically saved on a response, so for example if we wish to shopping cart data:</p>708+709+<pre><code>var RedisStore = require('connect-redis');710+app.use(express.cookieDecoder());711+app.use(express.session({ store: new RedisStore }));712+app.use(express.bodyDecoder());713+714+app.post('/add-to-cart', function(req, res){715+ // Perhaps we posted several items with a form716+ // (use the bodyDecoder() middleware for this)717+ var items = req.body.items;718+ req.session.items = items;719+ res.redirect('back');720+});721+722+app.get('/add-to-cart', function(req, res){723+ // When redirected back to GET /add-to-cart724+ // we could check req.session.items && req.session.items.length725+ // to print out a message726+ if (req.session.items && req.session.items.length) {727+ req.flash('info', 'You have %s items in your cart', req.session.items.length);728+ }729+ res.render('shopping-cart');730+});731+</code></pre>732+733+<p>The <em>req.session</em> object also has methods such as <em>Session#touch()</em>, <em>Session#destroy()</em>, <em>Session#regenerate()</em> among others to maintain and manipulate sessions. For more information view the <a href="http://senchalabs.github.com/connect/session.html">Connect Session</a> documentation.</p>734+735 <h3 id="req-header-key-defaultValue-">req.header(key[, defaultValue])</h3>736 737 <p>Get the case-insensitive request header <em>key</em>, with optional <em>defaultValue</em>:</p>738 456 unmodified lines