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
Provenance
- Commit
99b49d2- Tree
758ac96- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
6230ec5
2 files changed+124 added−9 removed
modified:docs/guide.html+123 added-8 removed
230 unmodified lines231 <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 lines1223 1224 <pre><code>res.cookie('rememberme', 'yes', { maxAge: 900000 });1225 </code></pre>1226 1225-<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>1228 1229 <pre><code>app.use(express.cookieParser());1230 1231 app.get('/', function(req, res){275 unmodified lines1507 <h3 id="app.helpers()">app.helpers(obj)</h3>1508 1509 <p>Registers static view helpers.</p>1510 1509-<p> app.helpers({</p>1510-1511-<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>1517 1516-<p> });</p>1517-1518 <p>Our view could now utilize the <em>firstName</em> and <em>lastName</em> variables,1519 as well as the <em>name()</em> function exposed.</p>1520 1521 <pre><code><%= name(firstName, lastName) %>1522 </code></pre>1523 1524+<p>Express also provides a few locals by default:</p>1525+1526+<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>1532+1533+<p>This method is aliased as <em>app.locals()</em>.</p>1534+1535 <h3 id="app.dynamichelpers()">app.dynamicHelpers(obj)</h3>1536 1537 <p>Registers dynamic view helpers. Dynamic view helpers1538 are simply functions which accept <em>req</em>, <em>res</em>, and are11 unmodified lines1550 1551 <pre><code><%= session.name %>1552 </code></pre>1553 1554+<h3 id="app.lookup">app.lookup</h3>1555+1556+<p> The <em>app.lookup</em> http methods returns an array of callback functions1557+ associated with the given <em>path</em>.</p>1558+1559+<p> Suppose we define the following routes:</p>1560+1561+<pre><code> app.get('/user/:id', function(){});1562+ app.put('/user/:id', function(){});1563+ app.get('/user/:id/:op?', function(){});1564+</code></pre>1565+1566+<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>1569+1570+<pre><code> app.lookup.get('/user/:id');1571+ // => [Function]1572+1573+ app.lookup.get('/user/:id/:op?');1574+ // => [Function]1575+1576+ app.lookup.put('/user/:id');1577+ // => [Function]1578+1579+ app.lookup.all('/user/:id');1580+ // => [Function, Function]1581+1582+ app.lookup.all('/hey');1583+ // => []1584+</code></pre>1585+1586+<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>1589+1590+<pre><code> app.lookup.get('/user');1591+ app.get('/user');1592+</code></pre>1593+1594+<p> Each function returned has the following properties:</p>1595+1596+<pre><code> var fn = app.get('/user/:id/:op?')[0];1597+1598+ fn.regexp1599+ // => /^\/user\/(?:([^\/]+?))(?:\/([^\/]+?))?\/?$/i1600+1601+ fn.keys1602+ // => ['id', 'op']1603+1604+ fn.path1605+ // => '/user/:id/:op?'1606+1607+ fn.method1608+ // => 'GET'1609+</code></pre>1610+1611+<h3 id="app.match">app.match</h3>1612+1613+<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>1617+1618+<p> Suppose we define the following routes:</p>1619+1620+<pre><code> app.get('/user/:id', function(){});1621+ app.put('/user/:id', function(){});1622+ app.get('/user/:id/:op?', function(){});1623+</code></pre>1624+1625+<p> Our match against <strong>GET</strong> will return two functions, since the <em>:op</em>1626+ in our second route is optional.</p>1627+1628+<pre><code> app.match.get('/user/1');1629+ // => [Function, Function]1630+</code></pre>1631+1632+<p> This second call returns only the callback for <em>/user/:id/:op?</em>.</p>1633+1634+<pre><code> app.match.get('/user/23/edit');1635+ // => [Function]1636+</code></pre>1637+1638+<p> We can also use <em>all()</em> to disregard the http method:</p>1639+1640+<pre><code> app.match.all('/user/20');1641+ // => [Function, Function, Function]1642+</code></pre>1643+1644+<p> Each function matched has the following properties:</p>1645+1646+<pre><code> var fn = app.match.get('/user/23/edit')[0];1647+1648+ fn.keys1649+ // => ['id', 'op']1650+1651+ fn.params1652+ // => { id: '23', op: 'edit' }1653+1654+ fn.method1655+ // => 'GET'1656+</code></pre>1657+1658 <h3 id="app.mounted()">app.mounted(fn)</h3>1659 1660 <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 linesmodified:docs/index.html+1 added-1 removed
235 unmodified lines236 237 <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>243 244 16 unmodified lines