Skip to content
Myr

api.html

This file

Path

docs/api.html

1,088 lines · 68.8 KiB · HTML

Last changed by

Updated docsTj Holowaychukbefore adoption4d32762

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>

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 340why, one step back
340</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 341why, one step back
341<td class="docs">

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 342–343why, one step back
342<p>Module dependencies.
343 </p>

More docsTj Holowaychukbefore adoptionbedff32

lines 344–345why, one step back
344</td>
345<td class="code">

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

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

More docsTj Holowaychukbefore adoptionbedff32

lines 348–364why, one step back
348 <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),
349 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),350 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,351 <span class="class">Buffer</span> = <span class="variable">require</span>(<span class="string">'buffer'</span>).<span class="class">Buffer</span>;</code></pre>352</td>353</tr>354<tr class="code">355<td class="docs">356<p>Send a response with the given <code>body</code> and optional <code>headers</code> and <code>status</code> code.</p>357358<h2>Examples</h2>359360<pre><code>res.send(new Buffer('wahoo'));361res.send({ some: 'json' });362res.send('&lt;p&gt;some html&lt;/p&gt;');363res.send('Sorry, cant find that', 404);364res.send('text', { 'Content-Type': 'text/plain' }, 201);

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

lines 366–368why, one step back
366
367<h2></h2>368

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 369why, one step back
369<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 370–396why, one step back
370</td>
371<td class="code">372<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>){373 <span class="comment">// Allow status as second arg</span>374 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">headers</span> === <span class="string">'number'</span>) {375 <span class="variable">status</span> = <span class="variable">headers</span>,376 <span class="variable">headers</span> = <span class="keyword">null</span>;377 }378379 <span class="comment">// Defaults</span>380 <span class="variable">status</span> = <span class="variable">status</span> || <span class="number integer">200</span>;381 <span class="variable">headers</span> = <span class="variable">headers</span> || {};382383 <span class="comment">// Determine content type</span>384 <span class="keyword">switch</span> (<span class="keyword">typeof</span> <span class="variable">body</span>) {385 <span class="keyword">case</span> <span class="string">'number'</span>:386 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {387 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.txt'</span>);388 }389 <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>];390 <span class="keyword">break</span>;391 <span class="keyword">case</span> <span class="string">'string'</span>:392 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {393 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.html'</span>);394 }395 <span class="keyword">break</span>;396 <span class="keyword">case</span> <span class="string">'object'</span>:

More docs :)Tj Holowaychukbefore adoption0c5fe61

line 397why, one step back
397 <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 398why, one step back
398 <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 399–402why, one step back
399 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.bin'</span>);
400 }401 } <span class="keyword">else</span> {402 <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 403–427why, one step back
403 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.json'</span>);
404 }405 <span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">stringify</span>(<span class="variable">body</span>);406 }407 <span class="keyword">break</span>;408 }409410 <span class="comment">// Populate Content-Length</span>411 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Length'</span>]) {412 <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>413 ? <span class="variable">body</span>.<span class="variable">length</span>414 : <span class="class">Buffer</span>.<span class="variable">byteLength</span>(<span class="variable">body</span>));415 }416417 <span class="comment">// Merge headers passed</span>418 <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>);419420 <span class="comment">// Respond</span>421 <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>);422 <span class="this">this</span>.<span class="variable">end</span>(<span class="variable">body</span>);423};</code></pre>424</td>425</tr>426<tr class="code">427<td class="docs">

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

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

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 433why, one step back
433<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 434–452why, one step back
434</td>
435<td class="code">436<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>){437 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;438 <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>){439 <span class="keyword">if</span> (<span class="variable">err</span>) {440 <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>441 ? <span class="number integer">404</span>442 : <span class="number integer">500</span>);443 } <span class="keyword">else</span> {444 <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">file</span>);445 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">buf</span>);446 }447 });448};</code></pre>449</td>450</tr>451<tr class="code">452<td class="docs">

More docsTj Holowaychukbefore adoptionbedff32

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

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

lines 460–462why, one step back
460
461<h2></h2>462

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 463why, one step back
463<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 464–476why, one step back
464</td>
465<td class="code">466<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>){467 <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>));468};</code></pre>469</td>470</tr>471<tr class="code">472<td class="docs">473<p>Set <em>Content-Disposition</em> header to <em>attachment</em> with optional <code>filename</code>.</p>474475<h2></h2>476

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 477why, one step back
477<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 478–489why, one step back
478</td>
479<td class="code">480<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>){481 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Disposition'</span>, <span class="variable">filename</span>482 ? <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>483 : <span class="string">'attachment'</span>);484 <span class="keyword">return</span> <span class="this">this</span>;485};</code></pre>486</td>487</tr>488<tr class="code">489<td class="docs">

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

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

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 494why, one step back
494<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 495–503why, one step back
495</td>
496<td class="code">497<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>){498 <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>);499};</code></pre>500</td>501</tr>502<tr class="code">503<td class="docs">

More docsTj Holowaychukbefore adoptionbedff32

lines 504–507why, one step back
504<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>
505506<h2></h2>507

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 508why, one step back
508<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 509–523why, one step back
509</td>
510<td class="code">511<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>){512 <span class="keyword">return</span> <span class="variable">val</span> === <span class="variable">undefined</span>513 ? <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>]514 : <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] = <span class="variable">val</span>;515};</code></pre>516</td>517</tr>518<tr class="code">519<td class="docs">520<p>Redirect to the given <code>url</code> with optional response <code>status</code>521defauling to 302.</p>522523<p>The given <code>url</code> can also be the name of a mapped url, for

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

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

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

lines 529–534why, one step back
529
530<h2>Redirect Mapping</h2>531532<p> To extend the redirect mapping capabilities that Express provides,533 we may use the <code>app.redirect()</code> method:</p>534

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

lines 536–538why, one step back
536
537<p> Now in a route we may call:</p>538

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

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

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

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

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

More docsTj Holowaychukbefore adoptionbedff32

lines 554–556why, one step back
554
555<h2></h2>556

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 557why, one step back
557<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 558–580why, one step back
558</td>
559<td class="code">560<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>){561 <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>;562563 <span class="comment">// Setup redirect map</span>564 <span class="keyword">var</span> <span class="variable">map</span> = {565 <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>,566 <span class="variable">home</span>: <span class="variable">basePath</span>567 };568569 <span class="comment">// Support custom redirect map</span>570 <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>;571572 <span class="comment">// Attempt mapped redirect</span>573 <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>574 ? <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>)575 : <span class="variable">map</span>[<span class="variable">url</span>];576577 <span class="comment">// Perform redirect</span>578 <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> });579 <span class="this">this</span>.<span class="variable">end</span>();580};

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

lines 581–582why, one step back
581</code></pre>
582</td>

Updated docsTj Holowaychukbefore adoption6a0ade0

line 583why, one step back
583</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 584why, one step back
584<td class="docs">

Updated docsTj Holowaychukbefore adoption6a0ade0

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

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

line 588why, one step back
588

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 589–591why, one step back
589<p> <em>foo</em> or <em>foo</em> become &lt;em&gt;foo&lt;/em&gt;
590 <strong>foo</strong> or <strong>foo</strong> become &lt;strong&gt;foo&lt;/strong&gt;591 <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 592–594why, one step back
592
593<h2></h2>594

Updated docsTj Holowaychukbefore adoption6a0ade0

line 595why, one step back
595<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 596–597why, one step back
596</td>
597<td class="code">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 598–602why, one step back
598<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){
599 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)600 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)601 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)602 .<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 603–607why, one step back
603};</code></pre>
604</td>605</tr>606<tr class="code">607<td class="docs">

Updated docsTj Holowaychukbefore adoption6a0ade0

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

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 609–611why, one step back
609
610<h2></h2>611

Updated docsTj Holowaychukbefore adoption6a0ade0

line 612why, one step back
612<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 613–614why, one step back
613</td>
614<td class="code">

Updated docsTj Holowaychukbefore adoption6a0ade0

lines 615–620why, one step back
615<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {
616 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)617 .<span class="variable">replace</span>(<span class="regexp">/&amp;/g</span>, <span class="string">'&amp;'</span>)618 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)619 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)620 .<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 621why, one step back
621};</code></pre>

Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f

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

Updated docsTj Holowaychukbefore adoption4d32762

lines 623–855why, one step back
623</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">
624<td class="docs">625<p>Module dependencies.626 </p>627</td>628<td class="code">629<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),630 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),631 <span class="variable">view</span> = <span class="variable">require</span>(<span class="string">'./view'</span>),632 <span class="variable">connect</span> = <span class="variable">require</span>(<span class="string">'connect'</span>),633 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),634 <span class="variable">queryString</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>),635 <span class="variable">router</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/router'</span>);</code></pre>636</td>637</tr>638<tr class="code">639<td class="docs">640<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>641642<h2></h2>643644<ul><li><p><strong>param</strong>: <em>Array</em> middleware</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>645</td>646<td class="code">647<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>){648 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;649 <span class="this">this</span>.<span class="variable">config</span> = {};650 <span class="this">this</span>.<span class="variable">settings</span> = {};651 <span class="this">this</span>.<span class="variable">redirects</span> = {};652 <span class="this">this</span>.<span class="variable">viewHelpers</span> = {};653 <span class="this">this</span>.<span class="variable">dynamicViewHelpers</span> = {};654 <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> || []);655656 <span class="comment">// Expose objects to each other</span>657 <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>){658 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};659 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};660 <span class="variable">res</span>.<span class="variable">headers</span> = {};661 <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>;662 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;663 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;664 <span class="comment">// Assign req.params.get</span>665 <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>) {666 <span class="comment">// TODO: consider simple substr to increase performance</span>667 <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>;668 <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>);669 }670 <span class="variable">next</span>();671 });672673 <span class="comment">// Use router, expose as app.get(), etc</span>674 <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>; });675};</code></pre>676</td>677</tr>678<tr class="code">679<td class="docs">680<p>Inherit from <code>connect.Server</code>.681 </p>682</td>683<td class="code">684<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>685</td>686</tr>687<tr class="code">688<td class="docs">689<p>Start listening on the given <code>port</code> / <code>host</code>.</p>690691<h2></h2>692693<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>694</td>695<td class="code">696<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>){697 <span class="comment">// Default &quot;home&quot; to the mounted route or '/'</span>698 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>)) {699 <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>, <span class="this">this</span>.<span class="variable">route</span> || <span class="string">'/'</span>);700 }701702 <span class="comment">// Set &quot;env&quot; to {EXPRESS,CONNECT}_ENV</span>703 <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>);704 <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>));705706 <span class="comment">// Setup view reloading</span>707 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {708 <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>));709 }710711 <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>);712};</code></pre>713</td>714</tr>715<tr class="code">716<td class="docs">717<p>Register the given view helpers <code>obj</code>. This method718can be called several times to apply additional helpers.</p>719720<h2></h2>721722<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>723</td>724<td class="code">725<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>){726 <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>);727 <span class="keyword">return</span> <span class="this">this</span>;728};</code></pre>729</td>730</tr>731<tr class="code">732<td class="docs">733<p>Register the given dynamic view helpers <code>obj</code>. This method734can be called several times to apply additional helpers.</p>735736<h2></h2>737738<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>739</td>740<td class="code">741<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>){742 <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>);743 <span class="keyword">return</span> <span class="this">this</span>;744};</code></pre>745</td>746</tr>747<tr class="code">748<td class="docs">749<p>Assign a custom exception handler callback <code>fn</code>.</p>750751<h2></h2>752753<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>754</td>755<td class="code">756<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>){757 <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>){758 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);759 });760 <span class="keyword">return</span> <span class="this">this</span>;761};</code></pre>762</td>763</tr>764<tr class="code">765<td class="docs">766<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>767768<h2></h2>769770<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>771</td>772<td class="code">773<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>){774 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {775 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];776 } <span class="keyword">else</span> {777 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;778 <span class="keyword">return</span> <span class="this">this</span>;779 }780};</code></pre>781</td>782</tr>783<tr class="code">784<td class="docs">785<p>Enable <code>setting</code>.</p>786787<h2></h2>788789<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>790</td>791<td class="code">792<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>){793 <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>);794};</code></pre>795</td>796</tr>797<tr class="code">798<td class="docs">799<p>Disable <code>setting</code>.</p>800801<h2></h2>802803<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>804</td>805<td class="code">806<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>){807 <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>);808};</code></pre>809</td>810</tr>811<tr class="code">812<td class="docs">813<p>Redirect <code>key</code> to <code>url</code>.</p>814815<h2></h2>816817<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>818</td>819<td class="code">820<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>){821 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;822 <span class="keyword">return</span> <span class="this">this</span>;823};</code></pre>824</td>825</tr>826<tr class="code">827<td class="docs">828<p>Disable <code>setting</code>.</p>829830<h2></h2>831832<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>833</td>834<td class="code">835<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>){836 <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>;837 (<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>);838 <span class="keyword">return</span> <span class="this">this</span>;839};840841<span class="comment">// Generate routing methods</span>842843(<span class="keyword">function</span>(<span class="variable">method</span>){844 <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>){845 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {846 <span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);847 <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;848 }849 <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>);850 <span class="keyword">return</span> <span class="this">this</span>;851 };852 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;853})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);854</code></pre>855</td>

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 856why, one step back
856</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 857why, one step back
857<td class="docs">

Regenerated api docsTj Holowaychukbefore adoption69baa6e

lines 858–859why, one step back
858<p>Module dependencies.
859 </p>

More docs :)Tj Holowaychukbefore adoption0c5fe61

lines 860–861why, one step back
860</td>
861<td class="code">

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

lines 862–863why, one step back
862<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>,
863 <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 864why, one step back
864 <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 865why, one step back
865 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),

Regenerated docsTj Holowaychukbefore adoption09147a2

line 866why, one step back
866 <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 867–875why, one step back
867 <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>);</code></pre>
868</td>869</tr>870<tr class="code">871<td class="docs">872<p>Cache supported template engine exports to873increase performance by lowering the number874of calls to <code>require()</code>.</p>875

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

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

lines 877–878why, one step back
877</td>
878<td class="code">

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 879–884why, one step back
879<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = {};</code></pre>
880</td>881</tr>882<tr class="code">883<td class="docs">884<p>Cache view contents to prevent I/O hits.</p>

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

line 885why, one step back
885

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

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

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

Regenerated docsTj Holowaychukbefore adoption09147a2

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

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

lines 891–893why, one step back
891</tr>
892<tr class="code">893<td class="docs">

Regenerated docsTj Holowaychukbefore adoption09147a2

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

Regenerated api docsTj Holowaychukbefore adoption69baa6e

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

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 897–905why, one step back
897</td>
898<td class="code">899<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){900 <span class="variable">viewCache</span> = {};901};</code></pre>902</td>903</tr>904<tr class="code">905<td class="docs">

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

lines 906–909why, one step back
906<p>Render <code>view</code> partial with the given <code>options</code>.</p>
907908<h2>Options</h2>909

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

line 910why, one step back
910<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 911why, one step back
911For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li></ul>

Regenerated docsTj Holowaychukbefore adoption09147a2

line 912why, one step back
912

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

lines 913–914why, one step back
913<h2></h2>
914

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 915why, one step back
915<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 916–917why, one step back
916</td>
917<td class="code">

Regenerated docsTj Holowaychukbefore adoption09147a2

line 918why, one step back
918<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 919why, one step back
919 <span class="comment">// Inherit parent view extension when not present</span>

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 920–922why, one step back
920 <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>) {
921 <span class="variable">view</span> += <span class="variable">ext</span>;922 }

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

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

Updated docsTj Holowaychukbefore adoption4d32762

line 925why, one step back
925 <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">options</span>)) {

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 926–927why, one step back
926 <span class="variable">options</span> = { <span class="variable">collection</span>: <span class="variable">options</span> };
927 }

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

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

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

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

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

line 931why, one step back
931 <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 932–933why, one step back
932 <span class="variable">options</span>.<span class="variable">partial</span> = <span class="variable">true</span>;
933 <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 934–935why, one step back
934
935 <span class="comment">// Collection support</span>

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

lines 936–939why, one step back
936 <span class="keyword">var</span> <span class="variable">collection</span> = <span class="variable">options</span>.<span class="variable">collection</span>;
937 <span class="keyword">if</span> (<span class="variable">collection</span>) {938 <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>],939 <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 940–941why, one step back
940 <span class="keyword">delete</span> <span class="variable">options</span>.<span class="variable">collection</span>;
941 <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 942why, one step back
942 <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 943–951why, one step back
943 <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>;
944 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">indexInCollection</span> = <span class="variable">i</span>;945 <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>;946 <span class="variable">options</span>.<span class="variable">object</span> = <span class="variable">val</span>;947 <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>);948 }, <span class="this">this</span>).<span class="variable">join</span>(<span class="string">''</span>);949 } <span class="keyword">else</span> {950 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">object</span>) {951 <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 952why, one step back
952 <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 953why, one step back
953 <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 954why, one step back
954 } <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 955why, one step back
955 <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 956why, one step back
956 } <span class="keyword">else</span> {

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

line 957why, one step back
957 <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 958why, one step back
958 }

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

line 959why, one step back
959 }

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

lines 960–970why, one step back
960 <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>);
961 }962};</code></pre>963</td>964</tr>965<tr class="code">966<td class="docs">967<p>Render <code>view</code> with the given <code>options</code> and optional callback <code>fn</code>.968When a callback function is given a response will <em>not</em> be made969automatically, however otherwise a response of <em>200</em> and <em>text/html</em> is given.</p>970

Updated docsTj Holowaychukbefore adoption09dabef

lines 971–975why, one step back
971<h2>Options</h2>
972973<p> Most engines accept one or more of the following options,974 both <em>haml</em> and <em>jade</em> accept all:</p>975

More view docsTj Holowaychukbefore adoption1c8ff48

line 976why, one step back
976<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 977why, one step back
977

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

lines 978–979why, one step back
978<h2></h2>
979

Regenerated api docsTj Holowaychukbefore adoption69baa6e

line 980why, one step back
980<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 981–984why, one step back
981</td>
982<td class="code">983<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>){984 <span class="variable">options</span> = <span class="variable">options</span> || {};

Regenerated docsTj Holowaychukbefore adoption09147a2

line 985why, one step back
985 <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 986why, one step back
986

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 987–991why, one step back
987 <span class="comment">// Support &quot;view engine&quot; setting</span>
988 <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>) {989 <span class="variable">view</span> += <span class="string">'.'</span> + <span class="variable">defaultEngine</span>;990 }991

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

lines 992–993why, one step back
992 <span class="comment">// Defaults</span>
993 <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 994–995why, one step back
994 <span class="variable">helpers</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">viewHelpers</span>,
995 <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 996why, one step back
996 <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 997–1002why, one step back
997 <span class="variable">ext</span> = <span class="variable">extname</span>(<span class="variable">view</span>),
998 <span class="variable">partial</span> = <span class="variable">options</span>.<span class="variable">partial</span>,999 <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>,1000 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>1001 ? <span class="string">'layout'</span> + <span class="variable">ext</span>1002 : <span class="variable">layout</span>;

Updated docsTj Holowaychukbefore adoption09dabef

line 1003why, one step back
1003

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 1004–1008why, one step back
1004 <span class="comment">// Allow layout name without extension</span>
1005 <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>) {1006 <span class="variable">layout</span> += <span class="variable">ext</span>;1007 }1008

Updated docsTj Holowaychukbefore adoption4d32762

lines 1009–1010why, one step back
1009 <span class="comment">// Normalize &quot;context&quot; to &quot;scope&quot;, defaulting to this response</span>
1010 <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> || <span class="this">this</span>;

In depth partial docsTj Holowaychukbefore adoption793943f

line 1011why, one step back
1011

Updated docsTj Holowaychukbefore adoption09dabef

lines 1012–1015why, one step back
1012 <span class="comment">// Auto-cache in production</span>
1013 <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>) {1014 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;1015 }

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

lines 1016–1024why, one step back
1016
1017 <span class="comment">// Partials support</span>1018 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">partial</span>) {1019 <span class="variable">root</span> += <span class="string">'/partials'</span>;1020 }10211022 <span class="comment">// View path</span>1023 <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">root</span> + <span class="string">'/'</span> + <span class="variable">view</span>;1024

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 1025–1027why, one step back
1025 <span class="comment">// Pass filename to the engine and view</span>
1026 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};1027 <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 1028–1037why, one step back
1028
1029 <span class="comment">// Dynamic helper support</span>1030 <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>);1031 <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>) {1032 <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>],1033 <span class="variable">val</span> = <span class="variable">dynamicHelpers</span>[<span class="variable">key</span>];1034 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">val</span> === <span class="string">'function'</span>) {1035 <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>);1036 }1037 }

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 1038–1042why, one step back
1038
1039 <span class="comment">// Always expose partial() as a local</span>1040 <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>){1041 <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>);1042 };

Regenerated docsTj Holowaychukbefore adoption60cfd56

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

Started migration docsTj Holowaychukbefore adoption9e68a5b

line 1045why, one step back
1045 <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 1046why, one step back
1046

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

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

Regenerated docsTj Holowaychukbefore adoption09147a2

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

Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2

line 1057why, one step back
1057 <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 1058–1081why, one step back
1058 } <span class="keyword">catch</span> (<span class="variable">err</span>) {
1059 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1060 }10611062 <span class="comment">// Cache template engine exports</span>1063 <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>)));10641065 <span class="comment">// Attempt render</span>1066 <span class="keyword">try</span> {1067 <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>);1068 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1069 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1070 }10711072 <span class="comment">// Layout support</span>1073 <span class="keyword">if</span> (<span class="variable">layout</span>) {1074 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;1075 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">body</span> = <span class="variable">str</span>;1076 <span class="variable">self</span>.<span class="variable">render</span>(<span class="variable">layout</span>, <span class="variable">options</span>);1077 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">partial</span>) {1078 <span class="keyword">return</span> <span class="variable">str</span>;1079 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {1080 <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">str</span>);1081 } <span class="keyword">else</span> {

Updated docsTj Holowaychukbefore adoption4d32762

line 1082why, one step back
1082 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">str</span>);

Regenerated docsTj Holowaychukbefore adoption09147a2

lines 1083–1085why, one step back
1083 }
1084};1085</code></pre>

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

lines 1086–1088why, one step back
1086</td>
1087</tr> </body>1088</html></tbody></table>