Skip to content
Myr

updated docs

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 6230ec5 · Browse files · 2 files+124 added−9 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+124 added−9 removed

  • other:+124 added−9 removed

2 files+124 added−9 removed

modified:docs/guide.html+123 added-8 removed
230 unmodified lines
231<li><a href="#app.redirect()">redirect()</a></li>232<li><a href="#app.error()">error()</a></li>233<li><a href="#app.helpers()">helpers()</a></li>234<li><a href="#app.dynamichelpers()">dynamicHelpers()</a></li>235<li><a href="#app.lookup">lookup</a></li>236<li><a href="#app.match">match</a></li>237<li><a href="#app.mounted()">mounted()</a></li>238<li><a href="#app.register()">register()</a></li>239<li><a href="#app.listen()">listen()</a></li>240</ul></li>
982 unmodified lines
12231224<pre><code>res.cookie('rememberme', 'yes', { maxAge: 900000 });1225</code></pre>12261225<p>To parse incoming <em>Cookie</em> headers, use the <em>cookieDecoder</em> middleware, which provides the <em>req.cookies</em> object:</p>1227<p>To parse incoming <em>Cookie</em> headers, use the <em>cookieParser</em> middleware, which provides the <em>req.cookies</em> object:</p>12281229<pre><code>app.use(express.cookieParser());12301231app.get('/', function(req, res){
275 unmodified lines
1507<h3 id="app.helpers()">app.helpers(obj)</h3>15081509<p>Registers static view helpers.</p>15101509<p> app.helpers({</p>15101511<pre><code> name: function(first, last){ return first + ', ' + last }1512, firstName: 'tj'1513, lastName: 'holowaychuk'1511<pre><code>app.helpers({1512 name: function(first, last){ return first + ', ' + last }1513 , firstName: 'tj'1514 , lastName: 'holowaychuk'1515});1516</code></pre>15171516<p> });</p>15171518<p>Our view could now utilize the <em>firstName</em> and <em>lastName</em> variables,1519as well as the <em>name()</em> function exposed.</p>15201521<pre><code>&lt;%= name(firstName, lastName) %&gt;1522</code></pre>15231524<p>Express also provides a few locals by default:</p>15251526<pre><code>- `settings` the app's settings object1527- `filename` the view's filename1528- `request` the request object1529- `response` the response object1530- `app` the application itself1531</code></pre>15321533<p>This method is aliased as <em>app.locals()</em>.</p>15341535<h3 id="app.dynamichelpers()">app.dynamicHelpers(obj)</h3>15361537<p>Registers dynamic view helpers. Dynamic view helpers1538are simply functions which accept <em>req</em>, <em>res</em>, and are
11 unmodified lines
15501551<pre><code>&lt;%= session.name %&gt;1552</code></pre>15531554<h3 id="app.lookup">app.lookup</h3>15551556<p> The <em>app.lookup</em> http methods returns an array of callback functions1557 associated with the given <em>path</em>.</p>15581559<p> Suppose we define the following routes:</p>15601561<pre><code> app.get('/user/:id', function(){});1562 app.put('/user/:id', function(){});1563 app.get('/user/:id/:op?', function(){});1564</code></pre>15651566<p> We can utilize this lookup functionality to check which routes1567 have been defined, which can be extremely useful for higher level1568 frameworks built on Express.</p>15691570<pre><code> app.lookup.get('/user/:id');1571 // =&gt; [Function]15721573 app.lookup.get('/user/:id/:op?');1574 // =&gt; [Function]15751576 app.lookup.put('/user/:id');1577 // =&gt; [Function]15781579 app.lookup.all('/user/:id');1580 // =&gt; [Function, Function]15811582 app.lookup.all('/hey');1583 // =&gt; []1584</code></pre>15851586<p> To alias <em>app.lookup.VERB()</em>, we can simply invoke <em>app.VERB()</em>1587 without a callback, as a shortcut, for example the following are1588 equivalent:</p>15891590<pre><code> app.lookup.get('/user');1591 app.get('/user');1592</code></pre>15931594<p> Each function returned has the following properties:</p>15951596<pre><code> var fn = app.get('/user/:id/:op?')[0];15971598 fn.regexp1599 // =&gt; /^\/user\/(?:([^\/]+?))(?:\/([^\/]+?))?\/?$/i16001601 fn.keys1602 // =&gt; ['id', 'op']16031604 fn.path1605 // =&gt; '/user/:id/:op?'16061607 fn.method1608 // =&gt; 'GET'1609</code></pre>16101611<h3 id="app.match">app.match</h3>16121613<p> The <em>app.match</em> http methods return an array of callback functions1614 which match the given <em>url</em>, which may include a query string etc. This1615 is useful when you want reflect on which routes have the opportunity to1616 respond.</p>16171618<p> Suppose we define the following routes:</p>16191620<pre><code> app.get('/user/:id', function(){});1621 app.put('/user/:id', function(){});1622 app.get('/user/:id/:op?', function(){});1623</code></pre>16241625<p> Our match against <strong>GET</strong> will return two functions, since the <em>:op</em>1626 in our second route is optional.</p>16271628<pre><code> app.match.get('/user/1');1629 // =&gt; [Function, Function]1630</code></pre>16311632<p> This second call returns only the callback for <em>/user/:id/:op?</em>.</p>16331634<pre><code> app.match.get('/user/23/edit');1635 // =&gt; [Function]1636</code></pre>16371638<p> We can also use <em>all()</em> to disregard the http method:</p>16391640<pre><code> app.match.all('/user/20');1641 // =&gt; [Function, Function, Function]1642</code></pre>16431644<p> Each function matched has the following properties:</p>16451646<pre><code> var fn = app.match.get('/user/23/edit')[0];16471648 fn.keys1649 // =&gt; ['id', 'op']16501651 fn.params1652 // =&gt; { id: '23', op: 'edit' }16531654 fn.method1655 // =&gt; 'GET'1656</code></pre>16571658<h3 id="app.mounted()">app.mounted(fn)</h3>16591660<p>Assign a callback <em>fn</em> which is called when this <em>Server</em> is passed to <em>Server#use()</em>.</p>1661
76 unmodified lines
modified:docs/index.html+1 added-1 removed
235 unmodified lines
236237<ul>238<li><a href="http://github.com/visionmedia/express-resource">express-resource</a> provides resourceful routing</li>239<li><a href="http://github.com/visionmedia/express-messages">express-messages</a> flash message notification rendering</li>240<li><a href="http://github.com/visionmedia/express-configure">express-configure</a> async configuration support (load settings from redis etc)</li>240<li><a href="http://github.com/visionmedia/express-configuration">express-configure</a> async configuration support (load settings from redis etc)</li>241<li><a href="http://github.com/visionmedia/express-namespace">express-namespace</a> namespaced routing support</li>242</ul>243244
16 unmodified lines