api.html
This file
Path
docs/api.html
1,107 lines · 69.1 KiB · HTML
Last changed by
Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1
History of this fileTake 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 back1<html>2 <head>3 <title>Express</title>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 4why, one step back4 <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 back5 <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 back58 cursor: pointer;Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 59–88why, one step back59}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 back89 position: fixed;Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 90–98why, one step back90 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 back99 <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 back109 </head>110 <body>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 111why, one step back111<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 back112<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 113–114why, one step back113<p>Framework version.114 </p>Updated docsTj Holowaychukbefore adoption09dabef
lines 115–116why, one step back115</td>116<td class="code">Executable docsTj Holowaychukbefore adoption5e4d672
line 117why, one step back117<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 back118</td>119</tr>120<tr class="code">121<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 122–123why, one step back122<p>Module dependencies.123 </p>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 124–125why, one step back124</td>125<td class="code">Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2
line 126why, one step back126<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 back127</td>128</tr>129<tr class="code">130<td class="docs">131<p>Shortcut for <code>new Server(...)</code>.</p>132133<h2></h2>134Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 135why, one step back135<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 back136</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 back145<p>View extensions.146 </p>Updated docsTj Holowaychukbefore adoption09dabef
lines 147–153why, one step back147</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 back154</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// => "text/plain"173174req.header('content-type');175// => "text/plain"176177req.header('Accept');178// => undefined179180req.header('Accept', 'text/html');181// => "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// => true207208// Accept: text/*; application/json209req.accepts('html');210req.accepts('text/html');211req.accepts('text/plain');212req.accepts('application/json');213// => true214215req.accepts('image/png');216req.accepts('png');217// => 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('/') < 0) {236 type = mime.types['.' + type];237 }238 // Check if we have a direct match239 if (accept.indexOf(type) >= 0) {240 return true;241 // Check if we have type/<em>242 } else {243 type = type.split('/')[0] + '/</em>';244 return accept.indexOf(type) >= 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 // => 2291292 req.flash('info');293 // => ['email sent', 'email re-sent']294295 req.flash('info');296 // => []297298 req.flash();299 // => { 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 back340</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 back341<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 342–343why, one step back342<p>Module dependencies.343 </p>More docsTj Holowaychukbefore adoptionbedff32
lines 344–345why, one step back344</td>345<td class="code">Docs for new res methodsTj Holowaychukbefore adoptionb08dab9
lines 346–347why, one step back346<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 back348 <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('<p>some html</p>');363res.send('Sorry, cant find that', 404);364res.send('text', { 'Content-Type': 'text/plain' }, 201);Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 365why, one step back365res.send(404);</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 366–368why, one step back366367<h2></h2>368Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 369why, one step back369<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 back370</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 back397 <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 back398 <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 back399 <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 back403 <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 back428<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>432Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 433why, one step back433<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 back434</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 back453<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 back459// res.headers['Content-Type'] is now "image/png"</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 460–462why, one step back460461<h2></h2>462Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 463why, one step back463<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 back464</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>476Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 477why, one step back477<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 back478</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="'</span> + <span class="variable">path</span>.<span class="variable">basename</span>(<span class="variable">filename</span>) + <span class="string">'"'</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 back490<p>Transfer the given <code>file</code> with optional <code>filename</code> as an attachment.</p>491492<h2></h2>493Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 494why, one step back494<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 back495</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 back504<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>505506<h2></h2>507Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 508why, one step back508<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 back509</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, forRegenerated api docsTj Holowaychukbefore adoption69baa6e
lines 524–526why, one step back524example by default express supports "back" which redirects525to 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 back527which can be set via <code>app.set('home', '/blog');</code>, and defaultsRegenerated api docsTj Holowaychukbefore adoption69baa6e
line 528why, one step back528to '/'.</p>More docsTj Holowaychukbefore adoptionbedff32
lines 529–534why, one step back529530<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>534Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 535why, one step back535<pre><code>app.redirect('google', 'http://google.com');</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 536–538why, one step back536537<p> Now in a route we may call:</p>538Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 539why, one step back539<pre><code>res.redirect('google');</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 540–544why, one step back540541<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 back545 });</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 546–552why, one step back546547<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 back553 });</code></pre>More docsTj Holowaychukbefore adoptionbedff32
lines 554–556why, one step back554555<h2></h2>556Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 557why, one step back557<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 back558</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 back581</code></pre>582</td>Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 583–592why, one step back583</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">584<td class="docs">585<p>Module dependencies.586 </p>587</td>588<td class="code">589<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),590 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),591 <span class="variable">view</span> = <span class="variable">require</span>(<span class="string">'./view'</span>),592 <span class="variable">connect</span> = <span class="variable">require</span>(<span class="string">'connect'</span>),Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1
line 593why, one step back593 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 594–631why, one step back594 <span class="variable">queryString</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>),595 <span class="variable">router</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/router'</span>);</code></pre>596</td>597</tr>598<tr class="code">599<td class="docs">600<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>601602<h2></h2>603604<ul><li><p><strong>param</strong>: <em>Array</em> middleware</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>605</td>606<td class="code">607<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>){608 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;609 <span class="this">this</span>.<span class="variable">config</span> = {};610 <span class="this">this</span>.<span class="variable">settings</span> = {};611 <span class="this">this</span>.<span class="variable">redirects</span> = {};612 <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> || []);613614 <span class="comment">// Expose objects to each other</span>615 <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>){616 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};617 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};618 <span class="variable">res</span>.<span class="variable">headers</span> = {};619 <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>;620 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;621 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;622 <span class="comment">// Assign req.params.get</span>623 <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>) {624 <span class="comment">// TODO: consider simple substr to increase performance</span>625 <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>;626 <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>);627 }628 <span class="variable">next</span>();629 });630631 <span class="comment">// Use router, expose as app.get(), etc</span>Added view helper docs. Closes #344Tj Holowaychukbefore adoptionc4b5208
line 632why, one step back632 <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>; });Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 633–668why, one step back633};</code></pre>634</td>635</tr>636<tr class="code">637<td class="docs">638<p>Inherit from <code>connect.Server</code>.639 </p>640</td>641<td class="code">642<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>643</td>644</tr>645<tr class="code">646<td class="docs">647<p>Start listening on the given <code>port</code> / <code>host</code>.</p>648649<h2></h2>650651<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>652</td>653<td class="code">654<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>){655 <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>);656 <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>));657658 <span class="comment">// Setup view reloading</span>659 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {660 <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>));661 }662663 <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>);664};</code></pre>665</td>666</tr>667<tr class="code">668<td class="docs">Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 669–677why, one step back669<p>Register the given view helpers <code>obj</code>. This method670can be called several times to apply additional helpers.</p>671672<h2></h2>673674<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>675</td>676<td class="code">677<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>){Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1
lines 678–694why, one step back678 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">view</span>.<span class="variable">helpers</span>, <span class="variable">obj</span>);679 <span class="keyword">return</span> <span class="this">this</span>;680};</code></pre>681</td>682</tr>683<tr class="code">684<td class="docs">685<p>Register the given dynamic view helpers <code>obj</code>. This method686can be called several times to apply additional helpers.</p>687688<h2></h2>689690<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>691</td>692<td class="code">693<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>){694 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">view</span>.<span class="variable">dynamicHelpers</span>, <span class="variable">obj</span>);Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 695–700why, one step back695 <span class="keyword">return</span> <span class="this">this</span>;696};</code></pre>697</td>698</tr>699<tr class="code">700<td class="docs">Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 701–796why, one step back701<p>Assign a custom exception handler callback <code>fn</code>.</p>702703<h2></h2>704705<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>706</td>707<td class="code">708<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>){709 <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>){710 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);711 });712 <span class="keyword">return</span> <span class="this">this</span>;713};</code></pre>714</td>715</tr>716<tr class="code">717<td class="docs">718<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>719720<h2></h2>721722<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>723</td>724<td class="code">725<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>){726 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {727 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];728 } <span class="keyword">else</span> {729 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;730 <span class="keyword">return</span> <span class="this">this</span>;731 }732};</code></pre>733</td>734</tr>735<tr class="code">736<td class="docs">737<p>Enable <code>setting</code>.</p>738739<h2></h2>740741<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>742</td>743<td class="code">744<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>){745 <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>);746};</code></pre>747</td>748</tr>749<tr class="code">750<td class="docs">751<p>Disable <code>setting</code>.</p>752753<h2></h2>754755<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>756</td>757<td class="code">758<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>){759 <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>);760};</code></pre>761</td>762</tr>763<tr class="code">764<td class="docs">765<p>Redirect <code>key</code> to <code>url</code>.</p>766767<h2></h2>768769<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>770</td>771<td class="code">772<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>){773 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;774 <span class="keyword">return</span> <span class="this">this</span>;775};</code></pre>776</td>777</tr>778<tr class="code">779<td class="docs">780<p>Disable <code>setting</code>.</p>781782<h2></h2>783784<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>785</td>786<td class="code">787<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>){788 <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>;789 (<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>);790 <span class="keyword">return</span> <span class="this">this</span>;791};792793<span class="comment">// Generate routing methods</span>794795(<span class="keyword">function</span>(<span class="variable">method</span>){796 <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>){Added view helper docs. Closes #344Tj Holowaychukbefore adoptionc4b5208
lines 797–800why, one step back797 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {798 <span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);799 <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;800 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 801–807why, one step back801 <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>);802 <span class="keyword">return</span> <span class="this">this</span>;803 };804 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;805})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);806</code></pre>807</td>Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 808why, one step back808</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">Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
line 809why, one step back809<td class="docs">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 810–812why, one step back810<p>Parse mini markdown implementation.811The following conversions are supported,812primarily for the "flash" middleware:</p>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
line 813why, one step back813Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 814–816why, one step back814<p> <em>foo</em> or <em>foo</em> become <em>foo</em>815 <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>816 <a href="B">A</a> becomes <a href="B">A</a></p>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 817–819why, one step back817818<h2></h2>819Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 820why, one step back820<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>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 821–822why, one step back821</td>822<td class="code">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 823–827why, one step back823<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){824 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)825 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)826 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)827 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'<a href="$2">$1</a>'</span>);Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 828–832why, one step back828};</code></pre>829</td>830</tr>831<tr class="code">832<td class="docs">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 833why, one step back833<p>Escape special characters in the given string of html.</p>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 834–836why, one step back834835<h2></h2>836Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 837why, one step back837<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>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 838–839why, one step back838</td>839<td class="code">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 840–845why, one step back840<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {841 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)842 .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)843 .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)844 .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)845 .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 846–847why, one step back846};</code></pre>847</td>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 848why, one step back848</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 849why, one step back849<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 850–851why, one step back850<p>Module dependencies.851 </p>More docs :)Tj Holowaychukbefore adoption0c5fe61
lines 852–853why, one step back852</td>853<td class="code">Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 854–855why, one step back854<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>,855 <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 856why, one step back856 <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 857why, one step back857 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),Regenerated docsTj Holowaychukbefore adoption09147a2
line 858why, one step back858 <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 859–867why, one step back859 <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>);</code></pre>860</td>861</tr>862<tr class="code">863<td class="docs">864<p>Cache supported template engine exports to865increase performance by lowering the number866of calls to <code>require()</code>.</p>867Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 868why, one step back868<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 869–870why, one step back869</td>870<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 871–876why, one step back871<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = {};</code></pre>872</td>873</tr>874<tr class="code">875<td class="docs">876<p>Cache view contents to prevent I/O hits.</p>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 877why, one step back877Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 878why, one step back878<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 879why, one step back879</td>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 880–882why, one step back880<td class="code">881<pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>882</td>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 883–885why, one step back883</tr>884<tr class="code">885<td class="docs">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 886–887why, one step back886<p>Clear the view cache.</p>887Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 888why, one step back888<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 889–897why, one step back889</td>890<td class="code">891<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){892 <span class="variable">viewCache</span> = {};893};</code></pre>894</td>895</tr>896<tr class="code">897<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 898why, one step back898<p>View helpers merged with each render's locals.</p>Regenerated docsTj Holowaychukbefore adoption60cfd56
line 899why, one step back899Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 900why, one step back900<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 901–907why, one step back901</td>902<td class="code">903<pre><code><span class="keyword">var</span> <span class="variable">helpers</span> = <span class="variable">exports</span>.<span class="variable">helpers</span> = {};</code></pre>904</td>905</tr>906<tr class="code">907<td class="docs">Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 908–917why, one step back908<p>Dynamic view helper functions.</p>909910<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>911</td>912<td class="code">913<pre><code><span class="keyword">var</span> <span class="variable">dynamicHelpers</span> = <span class="variable">exports</span>.<span class="variable">dynamicHelpers</span> = {};</code></pre>914</td>915</tr>916<tr class="code">917<td class="docs">Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 918–921why, one step back918<p>Render <code>view</code> partial with the given <code>options</code>.</p>919920<h2>Options</h2>921Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 922why, one step back922<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 923why, one step back923For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li></ul>Regenerated docsTj Holowaychukbefore adoption09147a2
line 924why, one step back924Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 925–926why, one step back925<h2></h2>926Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 927why, one step back927<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 928–929why, one step back928</td>929<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
line 930why, one step back930<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 931why, one step back931 <span class="comment">// Inherit parent view extension when not present</span>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 932–934why, one step back932 <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>) {933 <span class="variable">view</span> += <span class="variable">ext</span>;934 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 935–936why, one step back935936 <span class="comment">// Allow collection to be passed as second param</span>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 937–939why, one step back937 <span class="keyword">if</span> (<span class="variable">options</span> <span class="variable">instanceof</span> <span class="class">Array</span>) {938 <span class="variable">options</span> = { <span class="variable">collection</span>: <span class="variable">options</span> };939 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 940–941why, one step back940941 <span class="comment">// Defaults</span>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 942why, one step back942 <span class="variable">options</span> = <span class="variable">options</span> || {};Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 943why, one step back943 <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 944–945why, one step back944 <span class="variable">options</span>.<span class="variable">partial</span> = <span class="variable">true</span>;945 <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 946–947why, one step back946947 <span class="comment">// Collection support</span>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 948–951why, one step back948 <span class="keyword">var</span> <span class="variable">collection</span> = <span class="variable">options</span>.<span class="variable">collection</span>;949 <span class="keyword">if</span> (<span class="variable">collection</span>) {950 <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>],951 <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 952–953why, one step back952 <span class="keyword">delete</span> <span class="variable">options</span>.<span class="variable">collection</span>;953 <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 954why, one step back954 <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 955–963why, one step back955 <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>;956 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">indexInCollection</span> = <span class="variable">i</span>;957 <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>;958 <span class="variable">options</span>.<span class="variable">object</span> = <span class="variable">val</span>;959 <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>);960 }, <span class="this">this</span>).<span class="variable">join</span>(<span class="string">''</span>);961 } <span class="keyword">else</span> {962 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">object</span>) {963 <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 964why, one step back964 <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 965why, one step back965 <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 966why, one step back966 } <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 967why, one step back967 <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 968why, one step back968 } <span class="keyword">else</span> {Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 969why, one step back969 <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 970why, one step back970 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 971why, one step back971 }Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 972–982why, one step back972 <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>);973 }974};</code></pre>975</td>976</tr>977<tr class="code">978<td class="docs">979<p>Render <code>view</code> with the given <code>options</code> and optional callback <code>fn</code>.980When a callback function is given a response will <em>not</em> be made981automatically, however otherwise a response of <em>200</em> and <em>text/html</em> is given.</p>982Updated docsTj Holowaychukbefore adoption09dabef
lines 983–987why, one step back983<h2>Options</h2>984985<p> Most engines accept one or more of the following options,986 both <em>haml</em> and <em>jade</em> accept all:</p>987More view docsTj Holowaychukbefore adoption1c8ff48
line 988why, one step back988<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 989why, one step back989Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 990–991why, one step back990<h2></h2>991Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 992why, one step back992<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 993–996why, one step back993</td>994<td class="code">995<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>){996 <span class="variable">options</span> = <span class="variable">options</span> || {};Regenerated docsTj Holowaychukbefore adoption09147a2
line 997why, one step back997 <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 998why, one step back998Regenerated docsTj Holowaychukbefore adoption09147a2
lines 999–1003why, one step back999 <span class="comment">// Support "view engine" setting</span>1000 <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>) {1001 <span class="variable">view</span> += <span class="string">'.'</span> + <span class="variable">defaultEngine</span>;1002 }1003Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1004–1005why, one step back1004 <span class="comment">// Defaults</span>1005 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,Regenerated docsTj Holowaychukbefore adoption09147a2
line 1006why, one step back1006 <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 1007–1012why, one step back1007 <span class="variable">ext</span> = <span class="variable">extname</span>(<span class="variable">view</span>),1008 <span class="variable">partial</span> = <span class="variable">options</span>.<span class="variable">partial</span>,1009 <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>,1010 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>1011 ? <span class="string">'layout'</span> + <span class="variable">ext</span>1012 : <span class="variable">layout</span>;Updated docsTj Holowaychukbefore adoption09dabef
line 1013why, one step back1013Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 1014–1018why, one step back1014 <span class="comment">// Allow layout name without extension</span>1015 <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>) {1016 <span class="variable">layout</span> += <span class="variable">ext</span>;1017 }1018In depth partial docsTj Holowaychukbefore adoption793943f
lines 1019–1021why, one step back1019 <span class="comment">// Normalize "context" to "scope"</span>1020 <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>;1021Updated docsTj Holowaychukbefore adoption09dabef
lines 1022–1025why, one step back1022 <span class="comment">// Auto-cache in production</span>1023 <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>) {1024 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;1025 }Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1026–1043why, one step back10261027 <span class="comment">// Partials support</span>1028 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">partial</span>) {1029 <span class="variable">root</span> += <span class="string">'/partials'</span>;1030 }10311032 <span class="comment">// View path</span>1033 <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">root</span> + <span class="string">'/'</span> + <span class="variable">view</span>;10341035 <span class="comment">// Send response</span>1036 <span class="keyword">function</span> <span class="variable">send</span>(<span class="variable">str</span>) {1037 <span class="variable">self</span>.<span class="variable">writeHead</span>(<span class="number integer">200</span>, {1038 <span class="string">'Content-Type'</span>: <span class="string">'text/html'</span>,1039 <span class="string">'Content-Length'</span>: <span class="variable">str</span>.<span class="variable">length</span>1040 });1041 <span class="variable">self</span>.<span class="variable">end</span>(<span class="variable">str</span>);1042 }1043Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1044–1046why, one step back1044 <span class="comment">// Pass filename to the engine and view</span>1045 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};1046 <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 1047–1056why, one step back10471048 <span class="comment">// Dynamic helper support</span>1049 <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>);1050 <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>) {1051 <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>],1052 <span class="variable">val</span> = <span class="variable">dynamicHelpers</span>[<span class="variable">key</span>];1053 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">val</span> === <span class="string">'function'</span>) {1054 <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>);1055 }1056 }Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1057–1061why, one step back10571058 <span class="comment">// Always expose partial() as a local</span>1059 <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>){1060 <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>);1061 };Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 1062–1063why, one step back1062 1063 <span class="comment">// Merge view helpers</span>Started migration docsTj Holowaychukbefore adoption9e68a5b
line 1064why, one step back1064 <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 1065why, one step back1065Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1066–1073why, one step back1066 <span class="keyword">function</span> <span class="variable">error</span>(<span class="variable">err</span>) {1067 <span class="keyword">if</span> (<span class="variable">fn</span>) {1068 <span class="variable">fn</span>(<span class="variable">err</span>);1069 } <span class="keyword">else</span> {1070 <span class="keyword">throw</span> <span class="variable">err</span>;1071 }1072 }1073Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1074–1075why, one step back1074 <span class="comment">// Cache contents</span>1075 <span class="keyword">try</span> {Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2
line 1076why, one step back1076 <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 1077–1104why, one step back1077 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1078 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1079 }10801081 <span class="comment">// Cache template engine exports</span>1082 <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>)));10831084 <span class="comment">// Attempt render</span>1085 <span class="keyword">try</span> {1086 <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>);1087 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1088 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1089 }10901091 <span class="comment">// Layout support</span>1092 <span class="keyword">if</span> (<span class="variable">layout</span>) {1093 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;1094 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">body</span> = <span class="variable">str</span>;1095 <span class="variable">self</span>.<span class="variable">render</span>(<span class="variable">layout</span>, <span class="variable">options</span>);1096 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">partial</span>) {1097 <span class="keyword">return</span> <span class="variable">str</span>;1098 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {1099 <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">str</span>);1100 } <span class="keyword">else</span> {1101 <span class="variable">send</span>(<span class="variable">str</span>);1102 }1103};1104</code></pre>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1105–1107why, one step back1105</td>1106</tr> </body>1107</html></tbody></table>