Skip to content
Myr

api.html

This file

Path

docs/api.html

1,091 lines · 68.9 KiB · HTML

Last changed by

Updated docsTj Holowaychukbefore adoption6a0ade0

History of this file

Take it

The walk stopped after 200 commits: lines older than 9750817 point at it.

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 1–3why, one step back
1<html>
2 <head>3 <title>Express</title>

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 4why, one step back
4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 5–57why, one step back
5 <style>body {
6 margin: 0;7 padding: 0;8 font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;9 color: #252519;10}11a {12 color: #252519;13}14a:hover {15 text-decoration: underline;16 color: #19469D;17}18p {19 margin: 12px 0;20}21h1, h2, h3 {22 margin: 0;23 padding: 0;24}25table#source {26 width: 100%;27 border-collapse: collapse;28}29table#source td:first-child {30 padding: 30px 40px 30px 40px;31 vertical-align: top;32}33table#source td:first-child,34table#source td:first-child pre {35 width: 450px;36}37table#source td:last-child {38 padding: 30px 0 30px 40px;39 border-left: 1px solid #E5E5EE;40 background: #F5F5FF;41}42table#source tr {43 border-bottom: 1px solid #E5E5EE;44}45table#source tr.filename {46 padding-top: 40px;47 border-top: 1px solid #E5E5EE;48}49table#source tr.filename td:first-child {50 text-transform: capitalize;51}52table#source tr.filename td:last-child {53 font-size: 12px;54}55table#source tr.filename h2 {56 margin: 0;57 padding: 0;

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 58why, one step back
58 cursor: pointer;

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 59–88why, one step back
59}
60table#source tr.code h1,61table#source tr.code h2,62table#source tr.code h3 {63 margin-top: 30px;64 font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;65 font-size: 18px;66}67table#source tr.code h2 {68 font-size: 16px;69}70table#source tr.code h3 {71 font-size: 14px;72}73table#source tr.code ul {74 margin: 15px 0 15px 35px;75 padding: 0;76}77table#source tr.code ul li {78 margin: 0;79 padding: 1px 0;80}81table#source tr.code ul li p {82 margin: 0;83 padding: 0;84}85table#source tr.code td:first-child pre {86 padding: 20px;87}88#ribbon {

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 89why, one step back
89 position: fixed;

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 90–98why, one step back
90 top: 0;
91 right: 0;92}93code .string { color: #219161; }94code .regexp { color: #219161; }95code .keyword { color: #954121; }96code .number { color: #19469D; }97code .comment { color: #bbb; }98code .this { color: #19469D; }</style>

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 99–108why, one step back
99 <script>
100 $(function(){101 $('tr.code').hide();102 $('tr.filename').toggle(function(){103 $(this).nextUntil('.filename').fadeIn();104 }, function(){105 $(this).nextUntil('.filename').fadeOut();106 });107 });108 </script>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 109–110why, one step back
109 </head>
110 <body>

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 111why, one step back
111<table id="source"><tbody><tr><td><h1>Express</h1><p>High performance web framework for <a href="http://nodejs.org">node</a>.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/express/index.js"><a href="#">index</a></h2></td><td>lib/express/index.js</td></tr><tr class="code">

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

line 112why, one step back
112<td class="docs">

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 113–114why, one step back
113<p>Framework version.
114 </p>

Updated docsTj Holowaychukbefore adoption09dabef

lines 115–116why, one step back
115</td>
116<td class="code">

Executable docsTj Holowaychukbefore adoption5e4d672

line 117why, one step back
117<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'1.0.0beta'</span>;</code></pre>

Updated docsTj Holowaychukbefore adoption09dabef

lines 118–121why, one step back
118</td>
119</tr>120<tr class="code">121<td class="docs">

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 122–123why, one step back
122<p>Module dependencies.
123 </p>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 124–125why, one step back
124</td>
125<td class="code">

Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2

line 126why, one step back
126<pre><code><span class="keyword">var</span> <span class="class">Server</span> = <span class="variable">exports</span>.<span class="class">Server</span> = <span class="variable">require</span>(<span class="string">'./server'</span>);</code></pre>

Updated docsTj Holowaychukbefore adoption09dabef

lines 127–134why, one step back
127</td>
128</tr>129<tr class="code">130<td class="docs">131<p>Shortcut for <code>new Server(...)</code>.</p>132133<h2></h2>134

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 135why, one step back
135<ul><li><p><strong>param</strong>: <em>Function</em> ...</p></li><li><p><strong>return</strong>: <em>Server</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Updated docsTj Holowaychukbefore adoption09dabef

lines 136–144why, one step back
136</td>
137<td class="code">138<pre><code><span class="variable">exports</span>.<span class="variable">createServer</span> = <span class="keyword">function</span>(){139 <span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Server</span>(<span class="class">Array</span>.<span class="variable">prototype</span>.<span class="variable">slice</span>.<span class="variable">call</span>(<span class="variable">arguments</span>));140};</code></pre>141</td>142</tr>143<tr class="code">144<td class="docs">

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 145–146why, one step back
145<p>View extensions.
146 </p>

Updated docsTj Holowaychukbefore adoption09dabef

lines 147–153why, one step back
147</td>
148<td class="code">149<pre><code><span class="variable">require</span>(<span class="string">'./view'</span>);150<span class="variable">require</span>(<span class="string">'./request'</span>);151<span class="variable">require</span>(<span class="string">'./response'</span>);152</code></pre>153</td>

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 154–339why, one step back
154</tr><tr class="filename"><td><h2 id="lib/express/request.js"><a href="#">request</a></h2></td><td>lib/express/request.js</td></tr><tr class="code">
155<td class="docs">156<p>Module dependencies.157 </p>158</td>159<td class="code">160<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),161 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'./utils'</span>),162 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>;</code></pre>163</td>164</tr>165<tr class="code">166<td class="docs">167<p>Return request header or optional default.</p>168169<h2>Examples</h2>170171<pre><code>req.header('Content-Type');172// =&gt; "text/plain"173174req.header('content-type');175// =&gt; "text/plain"176177req.header('Accept');178// =&gt; undefined179180req.header('Accept', 'text/html');181// =&gt; "text/html"</code></pre>182183<h2></h2>184185<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>String</em> defaultValue</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>186</td>187<td class="code">188<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">name</span>, <span class="variable">defaultValue</span>){189 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>.<span class="variable">toLowerCase</span>()] || <span class="variable">defaultValue</span>;190};</code></pre>191</td>192</tr>193<tr class="code">194<td class="docs">195<p>Check if the <em>Accept</em> header is present, and includes the given <code>type</code>.</p>196197<p>When the <em>Accept</em> header is not present <code>true</code> is returned. Otherwise198the given <code>type</code> is matched by an exact match, and then subtypes. You199may pass the subtype such as "html" which is then converted internally200to "text/html" using the mime lookup table.</p>201202<h2>Examples</h2>203204<pre><code>// Accept: text/html205req.accepts('html');206// =&gt; true207208// Accept: text/*; application/json209req.accepts('html');210req.accepts('text/html');211req.accepts('text/plain');212req.accepts('application/json');213// =&gt; true214215req.accepts('image/png');216req.accepts('png');217// =&gt; false</code></pre>218219<h2></h2>220221<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>222</td>223<td class="code">224<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">accepts</span> = <span class="keyword">function</span>(<span class="variable">type</span>){225 <span class="keyword">var</span> <span class="variable">accept</span> = <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Accept'</span>);226 <span class="keyword">if</span> (!<span class="variable">accept</span> || <span class="variable">accept</span> === '*</code></pre>227</td>228</tr>229<tr class="code">230<td class="docs">231<p>') {232 return true;233 } else if (type) {234 // Allow "html" vs "text/html" etc235 if (type.indexOf('/') &lt; 0) {236 type = mime.types['.' + type];237 }238 // Check if we have a direct match239 if (accept.indexOf(type) &gt;= 0) {240 return true;241 // Check if we have type/<em>242 } else {243 type = type.split('/')[0] + '/</em>';244 return accept.indexOf(type) &gt;= 0;245 }246 } else {247 return false;248 }249};</p>250251<p>/**252Return the value of param <code>name</code> when present.</p>253254<ul><li>Checks route placeholders, ex: <em>/user/:id</em></li><li>Checks query string params, ex: ?id=12</li><li>Checks urlencoded body params, ex: id=12</li></ul>255256<p>To utilize urlencoded request bodies, <code>req.body</code>257should be an object. This can be done by using258the <code>connect.bodyDecoder</code> middleware.</p>259260<h2></h2>261262<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>263</td>264<td class="code">265<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">param</span> = <span class="keyword">function</span>(<span class="variable">name</span>){266 <span class="comment">// Route params like /user/:id</span>267 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">params</span>.<span class="variable">path</span>[<span class="variable">name</span>] !== <span class="variable">undefined</span>) {268 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">params</span>.<span class="variable">path</span>[<span class="variable">name</span>]; 269 }270 <span class="comment">// Query string params</span>271 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">params</span>.<span class="variable">get</span>[<span class="variable">name</span>] !== <span class="variable">undefined</span>) {272 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">params</span>.<span class="variable">get</span>[<span class="variable">name</span>]; 273 }274 <span class="comment">// Request body params via connect.bodyDecoder</span>275 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">body</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="this">this</span>.<span class="variable">body</span>[<span class="variable">name</span>] !== <span class="variable">undefined</span>) {276 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">body</span>[<span class="variable">name</span>];277 }278};</code></pre>279</td>280</tr>281<tr class="code">282<td class="docs">283<p>Queue flash <code>msg</code> of the given <code>type</code>.</p>284285<h2>Examples</h2>286287<pre><code> req.flash('info', 'email sent');288 req.flash('error', 'email delivery failed');289 req.flash('info', 'email re-sent');290 // =&gt; 2291292 req.flash('info');293 // =&gt; ['email sent', 'email re-sent']294295 req.flash('info');296 // =&gt; []297298 req.flash();299 // =&gt; { error: ['email delivery failed'], info: [] }</code></pre>300301<h2></h2>302303<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li><li><p><strong>return</strong>: <em>Array | Object | Number</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>304</td>305<td class="code">306<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">flash</span> = <span class="keyword">function</span>(<span class="variable">type</span>, <span class="variable">msg</span>){307 <span class="keyword">var</span> <span class="variable">msgs</span> = <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> || {};308 <span class="keyword">if</span> (<span class="variable">type</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">msg</span>) {309 <span class="variable">msg</span> = <span class="variable">utils</span>.<span class="variable">miniMarkdown</span>(<span class="variable">utils</span>.<span class="variable">htmlEscape</span>(<span class="variable">msg</span>));310 <span class="keyword">return</span> (<span class="variable">msgs</span>[<span class="variable">type</span>] = <span class="variable">msgs</span>[<span class="variable">type</span>] || []).<span class="variable">push</span>(<span class="variable">msg</span>);311 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">type</span>) {312 <span class="keyword">var</span> <span class="variable">arr</span> = <span class="variable">msgs</span>[<span class="variable">type</span>];313 <span class="keyword">delete</span> <span class="variable">msgs</span>[<span class="variable">type</span>];314 <span class="keyword">return</span> <span class="variable">arr</span> || [];315 } <span class="keyword">else</span> {316 <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = {};317 <span class="keyword">return</span> <span class="variable">msgs</span>;318 }319};320321<span class="comment">// Callback for isXMLHttpRequest / xhr</span>322323<span class="keyword">function</span> <span class="variable">isxhr</span>() {324 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'X-Requested-With'</span>, <span class="string">''</span>).<span class="variable">toLowerCase</span>() === <span class="string">'xmlhttprequest'</span>;325}</code></pre>326</td>327</tr>328<tr class="code">329<td class="docs">330<p>Check if the request was an <em>XMLHttpRequest</em>.</p>331332<h2></h2>333334<ul><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>335</td>336<td class="code">337<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'isXMLHttpRequest'</span>, <span class="variable">isxhr</span>);338<span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'xhr'</span>, <span class="variable">isxhr</span>);</code></pre>339</td>

Updated docsTj Holowaychukbefore adoption6a0ade0

line 340why, one step back
340</tr><tr class="filename"><td><h2 id="lib/express/server.js"><a href="#">server</a></h2></td><td>lib/express/server.js</td></tr><tr class="code">

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

line 341why, one step back
341<td class="docs">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 342–357why, one step back
342<p>Module dependencies.
343 </p>344</td>345<td class="code">346<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),347 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),348 <span class="variable">view</span> = <span class="variable">require</span>(<span class="string">'./view'</span>),349 <span class="variable">connect</span> = <span class="variable">require</span>(<span class="string">'connect'</span>),350 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),351 <span class="variable">queryString</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>),352 <span class="variable">router</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/router'</span>);</code></pre>353</td>354</tr>355<tr class="code">356<td class="docs">357<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

line 358why, one step back
358

Updated docsTj Holowaychukbefore adoption6a0ade0

line 359why, one step back
359<h2></h2>

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

line 360why, one step back
360

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 361–407why, one step back
361<ul><li><p><strong>param</strong>: <em>Array</em> middleware</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
362</td>363<td class="code">364<pre><code><span class="keyword">var</span> <span class="class">Server</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Server</span>(<span class="variable">middleware</span>){365 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;366 <span class="this">this</span>.<span class="variable">config</span> = {};367 <span class="this">this</span>.<span class="variable">settings</span> = {};368 <span class="this">this</span>.<span class="variable">redirects</span> = {};369 <span class="this">this</span>.<span class="variable">viewHelpers</span> = {};370 <span class="this">this</span>.<span class="variable">dynamicViewHelpers</span> = {};371 <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">middleware</span> || []);372373 <span class="comment">// Expose objects to each other</span>374 <span class="this">this</span>.<span class="variable">use</span>(<span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){375 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};376 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};377 <span class="variable">res</span>.<span class="variable">headers</span> = {};378 <span class="variable">req</span>.<span class="variable">app</span> = <span class="variable">res</span>.<span class="variable">app</span> = <span class="variable">self</span>;379 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;380 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;381 <span class="comment">// Assign req.params.get</span>382 <span class="keyword">if</span> (<span class="variable">req</span>.<span class="variable">url</span>.<span class="variable">indexOf</span>(<span class="string">'?'</span>) &<span class="variable">gt</span>; <span class="number integer">0</span>) {383 <span class="comment">// TODO: consider simple substr to increase performance</span>384 <span class="keyword">var</span> <span class="variable">query</span> = <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">query</span>;385 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = <span class="variable">queryString</span>.<span class="variable">parse</span>(<span class="variable">query</span>);386 }387 <span class="variable">next</span>();388 });389390 <span class="comment">// Use router, expose as app.get(), etc</span>391 <span class="this">this</span>.<span class="variable">router</span> = <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){ <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>; });392};</code></pre>393</td>394</tr>395<tr class="code">396<td class="docs">397<p>Inherit from <code>connect.Server</code>.398 </p>399</td>400<td class="code">401<pre><code><span class="variable">sys</span>.<span class="variable">inherits</span>(<span class="class">Server</span>, <span class="variable">connect</span>.<span class="class">Server</span>);</code></pre>402</td>403</tr>404<tr class="code">405<td class="docs">406<p>Start listening on the given <code>port</code> / <code>host</code>.</p>407

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

lines 408–409why, one step back
408<h2></h2>
409

Updated docsTj Holowaychukbefore adoption6a0ade0

line 410why, one step back
410<ul><li><p><strong>param</strong>: <em>Number</em> port</p></li><li><p><strong>param</strong>: <em>String</em> host</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

lines 411–412why, one step back
411</td>
412<td class="code">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 413–422why, one step back
413<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span> = <span class="keyword">function</span>(<span class="variable">port</span>, <span class="variable">host</span>){
414 <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>, <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">EXPRESS_ENV</span> || <span class="variable">process</span>.<span class="variable">connectEnv</span>.<span class="variable">name</span>);415 <span class="this">this</span>.<span class="variable">runConfig</span>(<span class="string">'any'</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>));416417 <span class="comment">// Setup view reloading</span>418 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {419 <span class="variable">view</span>.<span class="variable">watcher</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>));420 }421422 <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="variable">port</span>, <span class="variable">host</span>);

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

lines 423–427why, one step back
423};</code></pre>
424</td>425</tr>426<tr class="code">427<td class="docs">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 428–429why, one step back
428<p>Register the given view helpers <code>obj</code>. This method
429can be called several times to apply additional helpers.</p>

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

lines 430–432why, one step back
430
431<h2></h2>432

Updated docsTj Holowaychukbefore adoption6a0ade0

line 433why, one step back
433<ul><li><p><strong>param</strong>: <em>Object</em> obj</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

lines 434–435why, one step back
434</td>
435<td class="code">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 436–438why, one step back
436<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">helpers</span> = <span class="keyword">function</span>(<span class="variable">obj</span>){
437 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="this">this</span>.<span class="variable">viewHelpers</span>, <span class="variable">obj</span>);438 <span class="keyword">return</span> <span class="this">this</span>;

Added Guillermo Rauch to the contributor listTj Holowaychukbefore adoption6cf4629

lines 439–440why, one step back
439};</code></pre>
440</td>

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 441–566why, one step back
441</tr>
442<tr class="code">443<td class="docs">444<p>Register the given dynamic view helpers <code>obj</code>. This method445can be called several times to apply additional helpers.</p>446447<h2></h2>448449<ul><li><p><strong>param</strong>: <em>Object</em> obj</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>450</td>451<td class="code">452<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">dynamicHelpers</span> = <span class="keyword">function</span>(<span class="variable">obj</span>){453 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="this">this</span>.<span class="variable">dynamicViewHelpers</span>, <span class="variable">obj</span>);454 <span class="keyword">return</span> <span class="this">this</span>;455};</code></pre>456</td>457</tr>458<tr class="code">459<td class="docs">460<p>Assign a custom exception handler callback <code>fn</code>.</p>461462<h2></h2>463464<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>465</td>466<td class="code">467<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">error</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){468 <span class="this">this</span>.<span class="variable">use</span>(<span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){469 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);470 });471 <span class="keyword">return</span> <span class="this">this</span>;472};</code></pre>473</td>474</tr>475<tr class="code">476<td class="docs">477<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>478479<h2></h2>480481<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Server | Mixed</em> for chaining, or the setting value</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>482</td>483<td class="code">484<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">set</span> = <span class="keyword">function</span>(<span class="variable">setting</span>, <span class="variable">val</span>){485 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {486 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];487 } <span class="keyword">else</span> {488 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;489 <span class="keyword">return</span> <span class="this">this</span>;490 }491};</code></pre>492</td>493</tr>494<tr class="code">495<td class="docs">496<p>Enable <code>setting</code>.</p>497498<h2></h2>499500<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>501</td>502<td class="code">503<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">enable</span> = <span class="keyword">function</span>(<span class="variable">setting</span>){504 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">set</span>(<span class="variable">setting</span>, <span class="variable">true</span>);505};</code></pre>506</td>507</tr>508<tr class="code">509<td class="docs">510<p>Disable <code>setting</code>.</p>511512<h2></h2>513514<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>515</td>516<td class="code">517<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">disable</span> = <span class="keyword">function</span>(<span class="variable">setting</span>){518 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">set</span>(<span class="variable">setting</span>, <span class="variable">false</span>);519};</code></pre>520</td>521</tr>522<tr class="code">523<td class="docs">524<p>Redirect <code>key</code> to <code>url</code>.</p>525526<h2></h2>527528<ul><li><p><strong>param</strong>: <em>String</em> key</p></li><li><p><strong>param</strong>: <em>String</em> url</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>529</td>530<td class="code">531<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">redirect</span> = <span class="keyword">function</span>(<span class="variable">key</span>, <span class="variable">url</span>){532 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;533 <span class="keyword">return</span> <span class="this">this</span>;534};</code></pre>535</td>536</tr>537<tr class="code">538<td class="docs">539<p>Disable <code>setting</code>.</p>540541<h2></h2>542543<ul><li><p><strong>param</strong>: <em>String</em> setting</p></li><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>544</td>545<td class="code">546<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">configure</span> = <span class="keyword">function</span>(<span class="variable">env</span>, <span class="variable">fn</span>){547 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">env</span> === <span class="string">'function'</span>) <span class="variable">fn</span> = <span class="variable">env</span>, <span class="variable">env</span> = <span class="string">'any'</span>;548 (<span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] || []).<span class="variable">push</span>(<span class="variable">fn</span>);549 <span class="keyword">return</span> <span class="this">this</span>;550};551552<span class="comment">// Generate routing methods</span>553554(<span class="keyword">function</span>(<span class="variable">method</span>){555 <span class="class">Server</span>.<span class="variable">prototype</span>[<span class="variable">method</span>] = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">fn</span>){556 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {557 <span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);558 <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;559 }560 <span class="this">this</span>.<span class="variable">routes</span>[<span class="variable">method</span>](<span class="variable">path</span>, <span class="variable">fn</span>);561 <span class="keyword">return</span> <span class="this">this</span>;562 };563 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;564})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);565</code></pre>566</td>

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 567why, one step back
567</tr><tr class="filename"><td><h2 id="lib/express/response.js"><a href="#">response</a></h2></td><td>lib/express/response.js</td></tr><tr class="code">

More docsTj Holowaychukbefore adoptionbedff32

line 568why, one step back
568<td class="docs">

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 569–570why, one step back
569<p>Module dependencies.
570 </p>

More docsTj Holowaychukbefore adoptionbedff32

lines 571–572why, one step back
571</td>
572<td class="code">

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

lines 573–574why, one step back
573<pre><code><span class="keyword">var</span> <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>),
574 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),

More docsTj Holowaychukbefore adoptionbedff32

lines 575–591why, one step back
575 <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),
576 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),577 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,578 <span class="class">Buffer</span> = <span class="variable">require</span>(<span class="string">'buffer'</span>).<span class="class">Buffer</span>;</code></pre>579</td>580</tr>581<tr class="code">582<td class="docs">583<p>Send a response with the given <code>body</code> and optional <code>headers</code> and <code>status</code> code.</p>584585<h2>Examples</h2>586587<pre><code>res.send(new Buffer('wahoo'));588res.send({ some: 'json' });589res.send('&lt;p&gt;some html&lt;/p&gt;');590res.send('Sorry, cant find that', 404);591res.send('text', { 'Content-Type': 'text/plain' }, 201);

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 592why, one step back
592res.send(404);</code></pre>

More docsTj Holowaychukbefore adoptionbedff32

lines 593–595why, one step back
593
594<h2></h2>595

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 596why, one step back
596<ul><li><p><strong>param</strong>: <em>String | Object | Number | Buffer</em> body or status</p></li><li><p><strong>param</strong>: <em>Object | Number</em> headers or status</p></li><li><p><strong>param</strong>: <em>Number</em> status</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

More docsTj Holowaychukbefore adoptionbedff32

lines 597–623why, one step back
597</td>
598<td class="code">599<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">send</span> = <span class="keyword">function</span>(<span class="variable">body</span>, <span class="variable">headers</span>, <span class="variable">status</span>){600 <span class="comment">// Allow status as second arg</span>601 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">headers</span> === <span class="string">'number'</span>) {602 <span class="variable">status</span> = <span class="variable">headers</span>,603 <span class="variable">headers</span> = <span class="keyword">null</span>;604 }605606 <span class="comment">// Defaults</span>607 <span class="variable">status</span> = <span class="variable">status</span> || <span class="number integer">200</span>;608 <span class="variable">headers</span> = <span class="variable">headers</span> || {};609610 <span class="comment">// Determine content type</span>611 <span class="keyword">switch</span> (<span class="keyword">typeof</span> <span class="variable">body</span>) {612 <span class="keyword">case</span> <span class="string">'number'</span>:613 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {614 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.txt'</span>);615 }616 <span class="variable">body</span> = <span class="variable">http</span>.<span class="class">STATUS_CODES</span>[<span class="variable">status</span> = <span class="variable">body</span>];617 <span class="keyword">break</span>;618 <span class="keyword">case</span> <span class="string">'string'</span>:619 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {620 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.html'</span>);621 }622 <span class="keyword">break</span>;623 <span class="keyword">case</span> <span class="string">'object'</span>:

More docs :)Tj Holowaychukbefore adoption0c5fe61

line 624why, one step back
624 <span class="keyword">if</span> (<span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>) {

More docsTj Holowaychukbefore adoptionbedff32

line 625why, one step back
625 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {

More docs :)Tj Holowaychukbefore adoption0c5fe61

lines 626–629why, one step back
626 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.bin'</span>);
627 }628 } <span class="keyword">else</span> {629 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {

More docsTj Holowaychukbefore adoptionbedff32

lines 630–654why, one step back
630 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.json'</span>);
631 }632 <span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">stringify</span>(<span class="variable">body</span>);633 }634 <span class="keyword">break</span>;635 }636637 <span class="comment">// Populate Content-Length</span>638 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Length'</span>]) {639 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Length'</span>, <span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>640 ? <span class="variable">body</span>.<span class="variable">length</span>641 : <span class="class">Buffer</span>.<span class="variable">byteLength</span>(<span class="variable">body</span>));642 }643644 <span class="comment">// Merge headers passed</span>645 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="this">this</span>.<span class="variable">headers</span>, <span class="variable">headers</span>);646647 <span class="comment">// Respond</span>648 <span class="this">this</span>.<span class="variable">writeHead</span>(<span class="variable">status</span>, <span class="this">this</span>.<span class="variable">headers</span>);649 <span class="this">this</span>.<span class="variable">end</span>(<span class="variable">body</span>);650};</code></pre>651</td>652</tr>653<tr class="code">654<td class="docs">

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

lines 655–659why, one step back
655<p>Transfer the given <code>file</code>. Automatically sets the <em>Content-Type</em>
656response header, and responds with 404 / 500 appropriately.</p>657658<h2></h2>659

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 660why, one step back
660<ul><li><p><strong>param</strong>: <em>String</em> file</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

lines 661–679why, one step back
661</td>
662<td class="code">663<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">sendfile</span> = <span class="keyword">function</span>(<span class="variable">file</span>){664 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;665 <span class="variable">fs</span>.<span class="variable">readFile</span>(<span class="variable">file</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">buf</span>){666 <span class="keyword">if</span> (<span class="variable">err</span>) {667 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">err</span>.<span class="variable">errno</span> === <span class="variable">process</span>.<span class="class">ENOENT</span>668 ? <span class="number integer">404</span>669 : <span class="number integer">500</span>);670 } <span class="keyword">else</span> {671 <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">file</span>);672 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">buf</span>);673 }674 });675};</code></pre>676</td>677</tr>678<tr class="code">679<td class="docs">

More docsTj Holowaychukbefore adoptionbedff32

lines 680–685why, one step back
680<p>Set <em>Content-Type</em> response header passed through <code>mime.type()</code>.</p>
681682<h2>Examples</h2>683684<pre><code>var filename = 'path/to/image.png';685res.contentType(filename);

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 686why, one step back
686// res.headers['Content-Type'] is now "image/png"</code></pre>

More docsTj Holowaychukbefore adoptionbedff32

lines 687–689why, one step back
687
688<h2></h2>689

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 690why, one step back
690<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>return</strong>: <em>String</em> the resolved mime type</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

More docsTj Holowaychukbefore adoptionbedff32

lines 691–703why, one step back
691</td>
692<td class="code">693<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">contentType</span> = <span class="keyword">function</span>(<span class="variable">type</span>){694 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Type'</span>, <span class="variable">mime</span>.<span class="variable">type</span>(<span class="variable">type</span>));695};</code></pre>696</td>697</tr>698<tr class="code">699<td class="docs">700<p>Set <em>Content-Disposition</em> header to <em>attachment</em> with optional <code>filename</code>.</p>701702<h2></h2>703

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 704why, one step back
704<ul><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

More docsTj Holowaychukbefore adoptionbedff32

lines 705–716why, one step back
705</td>
706<td class="code">707<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">attachment</span> = <span class="keyword">function</span>(<span class="variable">filename</span>){708 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Disposition'</span>, <span class="variable">filename</span>709 ? <span class="string">'attachment; filename=&quot;'</span> + <span class="variable">path</span>.<span class="variable">basename</span>(<span class="variable">filename</span>) + <span class="string">'&quot;'</span>710 : <span class="string">'attachment'</span>);711 <span class="keyword">return</span> <span class="this">this</span>;712};</code></pre>713</td>714</tr>715<tr class="code">716<td class="docs">

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

lines 717–720why, one step back
717<p>Transfer the given <code>file</code> with optional <code>filename</code> as an attachment.</p>
718719<h2></h2>720

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 721why, one step back
721<ul><li><p><strong>param</strong>: <em>String</em> file</p></li><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>Type</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

lines 722–730why, one step back
722</td>
723<td class="code">724<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">download</span> = <span class="keyword">function</span>(<span class="variable">file</span>, <span class="variable">filename</span>){725 <span class="this">this</span>.<span class="variable">attachment</span>(<span class="variable">filename</span> || <span class="variable">file</span>).<span class="variable">sendfile</span>(<span class="variable">file</span>);726};</code></pre>727</td>728</tr>729<tr class="code">730<td class="docs">

More docsTj Holowaychukbefore adoptionbedff32

lines 731–734why, one step back
731<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>
732733<h2></h2>734

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 735why, one step back
735<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

More docsTj Holowaychukbefore adoptionbedff32

lines 736–750why, one step back
736</td>
737<td class="code">738<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">name</span>, <span class="variable">val</span>){739 <span class="keyword">return</span> <span class="variable">val</span> === <span class="variable">undefined</span>740 ? <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>]741 : <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] = <span class="variable">val</span>;742};</code></pre>743</td>744</tr>745<tr class="code">746<td class="docs">747<p>Redirect to the given <code>url</code> with optional response <code>status</code>748defauling to 302.</p>749750<p>The given <code>url</code> can also be the name of a mapped url, for

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 751–753why, one step back
751example by default express supports "back" which redirects
752to the <em>Referrer</em> or <em>Referer</em> headers or the application's753"home" setting. Express also supports "home" out of the box,

More docsTj Holowaychukbefore adoptionbedff32

line 754why, one step back
754which can be set via <code>app.set('home', '/blog');</code>, and defaults

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 755why, one step back
755to '/'.</p>

More docsTj Holowaychukbefore adoptionbedff32

lines 756–761why, one step back
756
757<h2>Redirect Mapping</h2>758759<p> To extend the redirect mapping capabilities that Express provides,760 we may use the <code>app.redirect()</code> method:</p>761

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 762why, one step back
762<pre><code>app.redirect('google', 'http://google.com');</code></pre>

More docsTj Holowaychukbefore adoptionbedff32

lines 763–765why, one step back
763
764<p> Now in a route we may call:</p>765

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 766why, one step back
766<pre><code>res.redirect('google');</code></pre>

More docsTj Holowaychukbefore adoptionbedff32

lines 767–771why, one step back
767
768<p> We may also map dynamic redirects:</p>769770<pre><code> app.redirect('comments', function(req, res, params){771 return '/post/' + params.id + '/comments';

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 772why, one step back
772 });</code></pre>

More docsTj Holowaychukbefore adoptionbedff32

lines 773–779why, one step back
773
774<p> So now we may do the following, and the redirect will dynamically adjust to775 the context of the request. If we called this route with <em>GET /post/12</em> our776 redirect <em>Location</em> would be <em>/post/12/comments</em>.</p>777778<pre><code> app.get('/post/:id', function(req, res){779 res.redirect('comments');

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 780why, one step back
780 });</code></pre>

More docsTj Holowaychukbefore adoptionbedff32

lines 781–783why, one step back
781
782<h2></h2>783

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 784why, one step back
784<ul><li><p><strong>param</strong>: <em>String</em> url</p></li><li><p><strong>param</strong>: <em>Number</em> code</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

More docsTj Holowaychukbefore adoptionbedff32

lines 785–807why, one step back
785</td>
786<td class="code">787<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">redirect</span> = <span class="keyword">function</span>(<span class="variable">url</span>, <span class="variable">status</span>){788 <span class="keyword">var</span> <span class="variable">basePath</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>) || <span class="string">'/'</span>;789790 <span class="comment">// Setup redirect map</span>791 <span class="keyword">var</span> <span class="variable">map</span> = {792 <span class="variable">back</span>: <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referrer</span> || <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referer</span> || <span class="variable">basePath</span>,793 <span class="variable">home</span>: <span class="variable">basePath</span>794 };795796 <span class="comment">// Support custom redirect map</span>797 <span class="variable">map</span>.<span class="variable">__proto__</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">redirects</span>;798799 <span class="comment">// Attempt mapped redirect</span>800 <span class="keyword">var</span> <span class="variable">mapped</span> = <span class="keyword">typeof</span> <span class="variable">map</span>[<span class="variable">url</span>] === <span class="string">'function'</span>801 ? <span class="variable">map</span>[<span class="variable">url</span>](<span class="this">this</span>.<span class="variable">req</span>, <span class="this">this</span>, <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">path</span>)802 : <span class="variable">map</span>[<span class="variable">url</span>];803804 <span class="comment">// Perform redirect</span>805 <span class="this">this</span>.<span class="variable">writeHead</span>(<span class="variable">status</span> || <span class="number integer">302</span>, { <span class="string">'Location'</span>: <span class="variable">mapped</span> || <span class="variable">url</span> });806 <span class="this">this</span>.<span class="variable">end</span>();807};

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

lines 808–809why, one step back
808</code></pre>
809</td>

Updated docsTj Holowaychukbefore adoption6a0ade0

line 810why, one step back
810</tr><tr class="filename"><td><h2 id="lib/express/utils.js"><a href="#">utils</a></h2></td><td>lib/express/utils.js</td></tr><tr class="code">

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 811why, one step back
811<td class="docs">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 812–814why, one step back
812<p>Parse mini markdown implementation.
813The following conversions are supported,814primarily for the "flash" middleware:</p>

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 815why, one step back
815

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 816–818why, one step back
816<p> <em>foo</em> or <em>foo</em> become &lt;em&gt;foo&lt;/em&gt;
817 <strong>foo</strong> or <strong>foo</strong> become &lt;strong&gt;foo&lt;/strong&gt;818 <a href="B">A</a> becomes &lt;a href="B"&gt;A&lt;/a&gt;</p>

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 819–821why, one step back
819
820<h2></h2>821

Updated docsTj Holowaychukbefore adoption6a0ade0

line 822why, one step back
822<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 823–824why, one step back
823</td>
824<td class="code">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 825–829why, one step back
825<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){
826 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)827 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)828 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)829 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'&lt;a href=&quot;$2&quot;&gt;$1&lt;/a&gt;'</span>);

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 830–834why, one step back
830};</code></pre>
831</td>832</tr>833<tr class="code">834<td class="docs">

Updated docsTj Holowaychukbefore adoption6a0ade0

line 835why, one step back
835<p>Escape special characters in the given string of html.</p>

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 836–838why, one step back
836
837<h2></h2>838

Updated docsTj Holowaychukbefore adoption6a0ade0

line 839why, one step back
839<ul><li><p><strong>param</strong>: <em>String</em> html</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 840–841why, one step back
840</td>
841<td class="code">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 842–847why, one step back
842<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {
843 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)844 .<span class="variable">replace</span>(<span class="regexp">/&amp;/g</span>, <span class="string">'&amp;'</span>)845 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)846 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)847 .<span class="variable">replace</span>(<span class="regexp">/&gt;/g</span>, <span class="string">'&gt;'</span>);

Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1

line 848why, one step back
848};</code></pre>

Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f

line 849why, one step back
849</td>

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 850why, one step back
850</tr><tr class="filename"><td><h2 id="lib/express/view.js"><a href="#">view</a></h2></td><td>lib/express/view.js</td></tr><tr class="code">

More docs :)Tj Holowaychukbefore adoption0c5fe61

line 851why, one step back
851<td class="docs">

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 852–853why, one step back
852<p>Module dependencies.
853 </p>

More docs :)Tj Holowaychukbefore adoption0c5fe61

lines 854–855why, one step back
854</td>
855<td class="code">

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 856–857why, one step back
856<pre><code><span class="keyword">var</span> <span class="variable">extname</span> = <span class="variable">require</span>(<span class="string">'path'</span>).<span class="variable">extname</span>,
857 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,

Regenerated docsTj Holowaychukbefore adoption09147a2

line 858why, one step back
858 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

line 859why, one step back
859 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),

Regenerated docsTj Holowaychukbefore adoption09147a2

line 860why, one step back
860 <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 861–869why, one step back
861 <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>);</code></pre>
862</td>863</tr>864<tr class="code">865<td class="docs">866<p>Cache supported template engine exports to867increase performance by lowering the number868of calls to <code>require()</code>.</p>869

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 870why, one step back
870<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 871–872why, one step back
871</td>
872<td class="code">

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 873–878why, one step back
873<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = {};</code></pre>
874</td>875</tr>876<tr class="code">877<td class="docs">878<p>Cache view contents to prevent I/O hits.</p>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

line 879why, one step back
879

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 880why, one step back
880<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

line 881why, one step back
881</td>

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 882–884why, one step back
882<td class="code">
883<pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>884</td>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 885–887why, one step back
885</tr>
886<tr class="code">887<td class="docs">

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 888–889why, one step back
888<p>Clear the view cache.</p>
889

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 890why, one step back
890<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 891–899why, one step back
891</td>
892<td class="code">893<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){894 <span class="variable">viewCache</span> = {};895};</code></pre>896</td>897</tr>898<tr class="code">899<td class="docs">

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 900–903why, one step back
900<p>Render <code>view</code> partial with the given <code>options</code>.</p>
901902<h2>Options</h2>903

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 904why, one step back
904<ul><li><p><code>object</code> Single object with name derived from the view (unless <code>as</code> is present) </p></li><li><p><code>as</code> Variable name for each <code>collection</code> value, defaults to the view name.</p><ul><li>as: 'something' will add the <code>something</code> local variable</li><li>as: this will use the collection value as the template context</li><li><p>as: global will merge the collection value's properties with <code>locals</code></p></li></ul></li><li><p><code>collection</code> Array of objects, the name is derived from the view name itself.

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 905why, one step back
905For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li></ul>

Regenerated docsTj Holowaychukbefore adoption09147a2

line 906why, one step back
906

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 907–908why, one step back
907<h2></h2>
908

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 909why, one step back
909<ul><li><p><strong>param</strong>: <em>String</em> view</p></li><li><p><strong>param</strong>: <em>Object | Array</em> options or collection</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 910–911why, one step back
910</td>
911<td class="code">

Regenerated docsTj Holowaychukbefore adoption09147a2

line 912why, one step back
912<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>){

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 913why, one step back
913 <span class="comment">// Inherit parent view extension when not present</span>

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 914–916why, one step back
914 <span class="keyword">if</span> (<span class="variable">ext</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {
915 <span class="variable">view</span> += <span class="variable">ext</span>;916 }

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 917–918why, one step back
917
918 <span class="comment">// Allow collection to be passed as second param</span>

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 919–921why, one step back
919 <span class="keyword">if</span> (<span class="variable">options</span> <span class="variable">instanceof</span> <span class="class">Array</span>) {
920 <span class="variable">options</span> = { <span class="variable">collection</span>: <span class="variable">options</span> };921 }

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 922–923why, one step back
922
923 <span class="comment">// Defaults</span>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

line 924why, one step back
924 <span class="variable">options</span> = <span class="variable">options</span> || {};

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 925why, one step back
925 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 926–927why, one step back
926 <span class="variable">options</span>.<span class="variable">partial</span> = <span class="variable">true</span>;
927 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 928–929why, one step back
928
929 <span class="comment">// Collection support</span>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 930–933why, one step back
930 <span class="keyword">var</span> <span class="variable">collection</span> = <span class="variable">options</span>.<span class="variable">collection</span>;
931 <span class="keyword">if</span> (<span class="variable">collection</span>) {932 <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">options</span>.<span class="variable">as</span> || <span class="variable">view</span>.<span class="variable">split</span>(<span class="string">'.'</span>)[<span class="number integer">0</span>],933 <span class="variable">len</span> = <span class="variable">collection</span>.<span class="variable">length</span>;

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 934–935why, one step back
934 <span class="keyword">delete</span> <span class="variable">options</span>.<span class="variable">collection</span>;
935 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">collectionLength</span> = <span class="variable">len</span>;

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

line 936why, one step back
936 <span class="keyword">return</span> <span class="variable">collection</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">i</span>){

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 937–945why, one step back
937 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">firstInCollection</span> = <span class="variable">i</span> === <span class="number integer">0</span>;
938 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">indexInCollection</span> = <span class="variable">i</span>;939 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">lastInCollection</span> = <span class="variable">i</span> === <span class="variable">len</span> - <span class="number integer">1</span>;940 <span class="variable">options</span>.<span class="variable">object</span> = <span class="variable">val</span>;941 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">partial</span>(<span class="variable">view</span>, <span class="variable">options</span>);942 }, <span class="this">this</span>).<span class="variable">join</span>(<span class="string">''</span>);943 } <span class="keyword">else</span> {944 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">object</span>) {945 <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">options</span>.<span class="variable">as</span> || <span class="variable">view</span>.<span class="variable">split</span>(<span class="string">'.'</span>)[<span class="number integer">0</span>];

Regenerated docsTj Holowaychukbefore adoption09147a2

line 946why, one step back
946 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">name</span> === <span class="string">'string'</span>) {

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 947why, one step back
947 <span class="variable">options</span>.<span class="variable">locals</span>[<span class="variable">name</span>] = <span class="variable">options</span>.<span class="variable">object</span>;

Regenerated docsTj Holowaychukbefore adoption09147a2

line 948why, one step back
948 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">name</span> === <span class="variable">global</span>) {

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 949why, one step back
949 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">options</span>.<span class="variable">locals</span>, <span class="variable">options</span>.<span class="variable">object</span>);

Regenerated docsTj Holowaychukbefore adoption09147a2

line 950why, one step back
950 } <span class="keyword">else</span> {

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 951why, one step back
951 <span class="variable">options</span>.<span class="variable">context</span> = <span class="variable">options</span>.<span class="variable">object</span>;

Regenerated docsTj Holowaychukbefore adoption09147a2

line 952why, one step back
952 }

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

line 953why, one step back
953 }

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 954–964why, one step back
954 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">render</span>(<span class="variable">view</span>, <span class="variable">options</span>);
955 }956};</code></pre>957</td>958</tr>959<tr class="code">960<td class="docs">961<p>Render <code>view</code> with the given <code>options</code> and optional callback <code>fn</code>.962When a callback function is given a response will <em>not</em> be made963automatically, however otherwise a response of <em>200</em> and <em>text/html</em> is given.</p>964

Updated docsTj Holowaychukbefore adoption09dabef

lines 965–969why, one step back
965<h2>Options</h2>
966967<p> Most engines accept one or more of the following options,968 both <em>haml</em> and <em>jade</em> accept all:</p>969

More view docsTj Holowaychukbefore adoption1c8ff48

line 970why, one step back
970<ul><li><code>context|scope</code> Template evaluation context (<code>this</code>)</li><li><code>locals</code> Object containing local variables</li><li><code>filename</code> Filename used for the <code>cache</code> option</li><li><code>cache</code> Cache intermediate JavaScript in memory</li><li><code>debug</code> Output debugging information</li></ul>

Updated docsTj Holowaychukbefore adoption09dabef

line 971why, one step back
971

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 972–973why, one step back
972<h2></h2>
973

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 974why, one step back
974<ul><li><p><strong>param</strong>: <em>String</em> view</p></li><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 975–978why, one step back
975</td>
976<td class="code">977<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">render</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">fn</span>){978 <span class="variable">options</span> = <span class="variable">options</span> || {};

Regenerated docsTj Holowaychukbefore adoption09147a2

line 979why, one step back
979 <span class="keyword">var</span> <span class="variable">defaultEngine</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'view engine'</span>);

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

line 980why, one step back
980

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 981–985why, one step back
981 <span class="comment">// Support &quot;view engine&quot; setting</span>
982 <span class="keyword">if</span> (<span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">defaultEngine</span>) {983 <span class="variable">view</span> += <span class="string">'.'</span> + <span class="variable">defaultEngine</span>;984 }985

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 986–987why, one step back
986 <span class="comment">// Defaults</span>
987 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,

Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f

lines 988–989why, one step back
988 <span class="variable">helpers</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">viewHelpers</span>,
989 <span class="variable">dynamicHelpers</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">dynamicViewHelpers</span>,

Regenerated docsTj Holowaychukbefore adoption09147a2

line 990why, one step back
990 <span class="variable">root</span> = <span class="variable">viewRoot</span>(<span class="this">this</span>.<span class="variable">app</span>),

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 991–996why, one step back
991 <span class="variable">ext</span> = <span class="variable">extname</span>(<span class="variable">view</span>),
992 <span class="variable">partial</span> = <span class="variable">options</span>.<span class="variable">partial</span>,993 <span class="variable">layout</span> = <span class="variable">options</span>.<span class="variable">layout</span> === <span class="variable">undefined</span> ? <span class="variable">true</span> : <span class="variable">options</span>.<span class="variable">layout</span>,994 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>995 ? <span class="string">'layout'</span> + <span class="variable">ext</span>996 : <span class="variable">layout</span>;

Updated docsTj Holowaychukbefore adoption09dabef

line 997why, one step back
997

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 998–1002why, one step back
998 <span class="comment">// Allow layout name without extension</span>
999 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">layout</span> === <span class="string">'string'</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">layout</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {1000 <span class="variable">layout</span> += <span class="variable">ext</span>;1001 }1002

In depth partial docsTj Holowaychukbefore adoption793943f

lines 1003–1005why, one step back
1003 <span class="comment">// Normalize &quot;context&quot; to &quot;scope&quot;</span>
1004 <span class="variable">options</span>.<span class="variable">scope</span> = <span class="variable">options</span>.<span class="variable">scope</span> || <span class="variable">options</span>.<span class="variable">context</span>;1005

Updated docsTj Holowaychukbefore adoption09dabef

lines 1006–1009why, one step back
1006 <span class="comment">// Auto-cache in production</span>
1007 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'env'</span>) === <span class="string">'production'</span>) {1008 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;1009 }

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 1010–1027why, one step back
1010
1011 <span class="comment">// Partials support</span>1012 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">partial</span>) {1013 <span class="variable">root</span> += <span class="string">'/partials'</span>;1014 }10151016 <span class="comment">// View path</span>1017 <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">root</span> + <span class="string">'/'</span> + <span class="variable">view</span>;10181019 <span class="comment">// Send response</span>1020 <span class="keyword">function</span> <span class="variable">send</span>(<span class="variable">str</span>) {1021 <span class="variable">self</span>.<span class="variable">writeHead</span>(<span class="number integer">200</span>, {1022 <span class="string">'Content-Type'</span>: <span class="string">'text/html'</span>,1023 <span class="string">'Content-Length'</span>: <span class="variable">str</span>.<span class="variable">length</span>1024 });1025 <span class="variable">self</span>.<span class="variable">end</span>(<span class="variable">str</span>);1026 }1027

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 1028–1030why, one step back
1028 <span class="comment">// Pass filename to the engine and view</span>
1029 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};1030 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">__filename</span> = <span class="variable">options</span>.<span class="variable">filename</span> = <span class="variable">path</span>;

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 1031–1040why, one step back
1031
1032 <span class="comment">// Dynamic helper support</span>1033 <span class="keyword">var</span> <span class="variable">keys</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">dynamicHelpers</span>);1034 <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">keys</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {1035 <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>],1036 <span class="variable">val</span> = <span class="variable">dynamicHelpers</span>[<span class="variable">key</span>];1037 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">val</span> === <span class="string">'function'</span>) {1038 <span class="variable">helpers</span>[<span class="variable">key</span>] = <span class="variable">val</span>.<span class="variable">call</span>(<span class="this">this</span>.<span class="variable">app</span>, <span class="this">this</span>.<span class="variable">req</span>, <span class="this">this</span>, <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">path</span>);1039 }1040 }

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 1041–1045why, one step back
1041
1042 <span class="comment">// Always expose partial() as a local</span>1043 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>){1044 <span class="keyword">return</span> <span class="variable">self</span>.<span class="variable">partial</span>.<span class="variable">call</span>(<span class="variable">self</span>, <span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>);1045 };

Regenerated docsTj Holowaychukbefore adoption60cfd56

lines 1046–1047why, one step back
1046
1047 <span class="comment">// Merge view helpers</span>

Started migration docsTj Holowaychukbefore adoption9e68a5b

line 1048why, one step back
1048 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">__proto__</span> = <span class="variable">helpers</span>;

Regenerated docsTj Holowaychukbefore adoption09147a2

line 1049why, one step back
1049

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 1050–1057why, one step back
1050 <span class="keyword">function</span> <span class="variable">error</span>(<span class="variable">err</span>) {
1051 <span class="keyword">if</span> (<span class="variable">fn</span>) {1052 <span class="variable">fn</span>(<span class="variable">err</span>);1053 } <span class="keyword">else</span> {1054 <span class="keyword">throw</span> <span class="variable">err</span>;1055 }1056 }1057

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 1058–1059why, one step back
1058 <span class="comment">// Cache contents</span>
1059 <span class="keyword">try</span> {

Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2

line 1060why, one step back
1060 <span class="keyword">var</span> <span class="variable">str</span> = <span class="variable">viewCache</span>[<span class="variable">path</span>] || <span class="variable">cacheViewSync</span>(<span class="variable">path</span>);

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 1061–1088why, one step back
1061 } <span class="keyword">catch</span> (<span class="variable">err</span>) {
1062 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1063 }10641065 <span class="comment">// Cache template engine exports</span>1066 <span class="keyword">var</span> <span class="variable">engine</span> = <span class="variable">cache</span>[<span class="variable">ext</span>] || (<span class="variable">cache</span>[<span class="variable">ext</span>] = <span class="variable">require</span>(<span class="variable">ext</span>.<span class="variable">substr</span>(<span class="number integer">1</span>)));10671068 <span class="comment">// Attempt render</span>1069 <span class="keyword">try</span> {1070 <span class="keyword">var</span> <span class="variable">str</span> = <span class="variable">engine</span>.<span class="variable">render</span>(<span class="variable">str</span>, <span class="variable">options</span>);1071 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1072 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1073 }10741075 <span class="comment">// Layout support</span>1076 <span class="keyword">if</span> (<span class="variable">layout</span>) {1077 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;1078 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">body</span> = <span class="variable">str</span>;1079 <span class="variable">self</span>.<span class="variable">render</span>(<span class="variable">layout</span>, <span class="variable">options</span>);1080 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">partial</span>) {1081 <span class="keyword">return</span> <span class="variable">str</span>;1082 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {1083 <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">str</span>);1084 } <span class="keyword">else</span> {1085 <span class="variable">send</span>(<span class="variable">str</span>);1086 }1087};1088</code></pre>

Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817

lines 1089–1091why, one step back
1089</td>
1090</tr> </body>1091</html></tbody></table>