api.html
This file
Path
docs/api.html
1,091 lines · 68.9 KiB · HTML
Last changed by
Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
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–611why, 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> = {};Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
lines 612–613why, one step back612 <span class="this">this</span>.<span class="variable">viewHelpers</span> = {};613 <span class="this">this</span>.<span class="variable">dynamicViewHelpers</span> = {};Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 614–633why, one step back614 <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> || []);615616 <span class="comment">// Expose objects to each other</span>617 <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>){618 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};619 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};620 <span class="variable">res</span>.<span class="variable">headers</span> = {};621 <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>;622 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;623 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;624 <span class="comment">// Assign req.params.get</span>625 <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>) {626 <span class="comment">// TODO: consider simple substr to increase performance</span>627 <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>;628 <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>);629 }630 <span class="variable">next</span>();631 });632633 <span class="comment">// Use router, expose as app.get(), etc</span>Added view helper docs. Closes #344Tj Holowaychukbefore adoptionc4b5208
line 634why, one step back634 <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 635–670why, one step back635};</code></pre>636</td>637</tr>638<tr class="code">639<td class="docs">640<p>Inherit from <code>connect.Server</code>.641 </p>642</td>643<td class="code">644<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>645</td>646</tr>647<tr class="code">648<td class="docs">649<p>Start listening on the given <code>port</code> / <code>host</code>.</p>650651<h2></h2>652653<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>654</td>655<td class="code">656<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>){657 <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>);658 <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>));659660 <span class="comment">// Setup view reloading</span>661 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {662 <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>));663 }664665 <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>);666};</code></pre>667</td>668</tr>669<tr class="code">670<td class="docs">Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 671–679why, one step back671<p>Register the given view helpers <code>obj</code>. This method672can be called several times to apply additional helpers.</p>673674<h2></h2>675676<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>677</td>678<td class="code">679<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>){Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
line 680why, one step back680 <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>);Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1
lines 681–695why, one step back681 <span class="keyword">return</span> <span class="this">this</span>;682};</code></pre>683</td>684</tr>685<tr class="code">686<td class="docs">687<p>Register the given dynamic view helpers <code>obj</code>. This method688can be called several times to apply additional helpers.</p>689690<h2></h2>691692<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>693</td>694<td class="code">695<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>){Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
line 696why, one step back696 <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>);Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 697–702why, one step back697 <span class="keyword">return</span> <span class="this">this</span>;698};</code></pre>699</td>700</tr>701<tr class="code">702<td class="docs">Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 703–798why, one step back703<p>Assign a custom exception handler callback <code>fn</code>.</p>704705<h2></h2>706707<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>708</td>709<td class="code">710<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>){711 <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>){712 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);713 });714 <span class="keyword">return</span> <span class="this">this</span>;715};</code></pre>716</td>717</tr>718<tr class="code">719<td class="docs">720<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>721722<h2></h2>723724<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>725</td>726<td class="code">727<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>){728 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {729 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];730 } <span class="keyword">else</span> {731 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;732 <span class="keyword">return</span> <span class="this">this</span>;733 }734};</code></pre>735</td>736</tr>737<tr class="code">738<td class="docs">739<p>Enable <code>setting</code>.</p>740741<h2></h2>742743<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>744</td>745<td class="code">746<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>){747 <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>);748};</code></pre>749</td>750</tr>751<tr class="code">752<td class="docs">753<p>Disable <code>setting</code>.</p>754755<h2></h2>756757<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>758</td>759<td class="code">760<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>){761 <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>);762};</code></pre>763</td>764</tr>765<tr class="code">766<td class="docs">767<p>Redirect <code>key</code> to <code>url</code>.</p>768769<h2></h2>770771<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>772</td>773<td class="code">774<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>){775 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;776 <span class="keyword">return</span> <span class="this">this</span>;777};</code></pre>778</td>779</tr>780<tr class="code">781<td class="docs">782<p>Disable <code>setting</code>.</p>783784<h2></h2>785786<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>787</td>788<td class="code">789<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>){790 <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>;791 (<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>);792 <span class="keyword">return</span> <span class="this">this</span>;793};794795<span class="comment">// Generate routing methods</span>796797(<span class="keyword">function</span>(<span class="variable">method</span>){798 <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 799–802why, one step back799 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {800 <span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);801 <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;802 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 803–809why, one step back803 <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>);804 <span class="keyword">return</span> <span class="this">this</span>;805 };806 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;807})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);808</code></pre>809</td>Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 810why, one step back810</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 811why, one step back811<td class="docs">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 812–814why, one step back812<p>Parse mini markdown implementation.813The following conversions are supported,814primarily for the "flash" middleware:</p>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
line 815why, one step back815Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 816–818why, one step back816<p> <em>foo</em> or <em>foo</em> become <em>foo</em>817 <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>818 <a href="B">A</a> becomes <a href="B">A</a></p>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 819–821why, one step back819820<h2></h2>821Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 822why, one step back822<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 823–824why, one step back823</td>824<td class="code">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 825–829why, one step back825<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){826 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)827 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)828 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)829 .<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 830–834why, one step back830};</code></pre>831</td>832</tr>833<tr class="code">834<td class="docs">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 835why, one step back835<p>Escape special characters in the given string of html.</p>Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 836–838why, one step back836837<h2></h2>838Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
line 839why, one step back839<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 840–841why, one step back840</td>841<td class="code">Fixed reload views exampleTj Holowaychukbefore adoption5fcf971
lines 842–847why, one step back842<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {843 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)844 .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)845 .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)846 .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)847 .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f
lines 848–849why, one step back848};</code></pre>849</td>Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 850why, one step back850</tr><tr class="filename"><td><h2 id="lib/express/view.js"><a href="#">view</a></h2></td><td>lib/express/view.js</td></tr><tr class="code">More docs :)Tj Holowaychukbefore adoption0c5fe61
line 851why, one step back851<td class="docs">Regenerated api docsTj Holowaychukbefore adoption69baa6e
lines 852–853why, one step back852<p>Module dependencies.853 </p>More docs :)Tj Holowaychukbefore adoption0c5fe61
lines 854–855why, one step back854</td>855<td class="code">Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 856–857why, one step back856<pre><code><span class="keyword">var</span> <span class="variable">extname</span> = <span class="variable">require</span>(<span class="string">'path'</span>).<span class="variable">extname</span>,857 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,Regenerated docsTj Holowaychukbefore adoption09147a2
line 858why, one step back858 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 859why, one step back859 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),Regenerated docsTj Holowaychukbefore adoption09147a2
line 860why, one step back860 <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 861–869why, one step back861 <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>);</code></pre>862</td>863</tr>864<tr class="code">865<td class="docs">866<p>Cache supported template engine exports to867increase performance by lowering the number868of calls to <code>require()</code>.</p>869Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 870why, one step back870<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 871–872why, one step back871</td>872<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 873–878why, one step back873<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = {};</code></pre>874</td>875</tr>876<tr class="code">877<td class="docs">878<p>Cache view contents to prevent I/O hits.</p>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 879why, one step back879Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 880why, one step back880<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 881why, one step back881</td>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 882–884why, one step back882<td class="code">883<pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>884</td>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 885–887why, one step back885</tr>886<tr class="code">887<td class="docs">Regenerated docsTj Holowaychukbefore adoption09147a2
lines 888–889why, one step back888<p>Clear the view cache.</p>889Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 890why, one step back890<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 891–899why, one step back891</td>892<td class="code">893<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){894 <span class="variable">viewCache</span> = {};895};</code></pre>896</td>897</tr>898<tr class="code">899<td class="docs">Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 900–903why, one step back900<p>Render <code>view</code> partial with the given <code>options</code>.</p>901902<h2>Options</h2>903Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 904why, one step back904<ul><li><p><code>object</code> Single object with name derived from the view (unless <code>as</code> is present) </p></li><li><p><code>as</code> Variable name for each <code>collection</code> value, defaults to the view name.</p><ul><li>as: 'something' will add the <code>something</code> local variable</li><li>as: this will use the collection value as the template context</li><li><p>as: global will merge the collection value's properties with <code>locals</code></p></li></ul></li><li><p><code>collection</code> Array of objects, the name is derived from the view name itself. Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 905why, one step back905For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li></ul>Regenerated docsTj Holowaychukbefore adoption09147a2
line 906why, one step back906Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 907–908why, one step back907<h2></h2>908Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 909why, one step back909<ul><li><p><strong>param</strong>: <em>String</em> view</p></li><li><p><strong>param</strong>: <em>Object | Array</em> options or collection</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 910–911why, one step back910</td>911<td class="code">Regenerated docsTj Holowaychukbefore adoption09147a2
line 912why, one step back912<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>){Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 913why, one step back913 <span class="comment">// Inherit parent view extension when not present</span>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 914–916why, one step back914 <span class="keyword">if</span> (<span class="variable">ext</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {915 <span class="variable">view</span> += <span class="variable">ext</span>;916 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 917–918why, one step back917918 <span class="comment">// Allow collection to be passed as second param</span>Regenerated docsTj Holowaychukbefore adoption09147a2
lines 919–921why, one step back919 <span class="keyword">if</span> (<span class="variable">options</span> <span class="variable">instanceof</span> <span class="class">Array</span>) {920 <span class="variable">options</span> = { <span class="variable">collection</span>: <span class="variable">options</span> };921 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 922–923why, one step back922923 <span class="comment">// Defaults</span>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 924why, one step back924 <span class="variable">options</span> = <span class="variable">options</span> || {};Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 925why, one step back925 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 926–927why, one step back926 <span class="variable">options</span>.<span class="variable">partial</span> = <span class="variable">true</span>;927 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 928–929why, one step back928929 <span class="comment">// Collection support</span>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 930–933why, one step back930 <span class="keyword">var</span> <span class="variable">collection</span> = <span class="variable">options</span>.<span class="variable">collection</span>;931 <span class="keyword">if</span> (<span class="variable">collection</span>) {932 <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">options</span>.<span class="variable">as</span> || <span class="variable">view</span>.<span class="variable">split</span>(<span class="string">'.'</span>)[<span class="number integer">0</span>],933 <span class="variable">len</span> = <span class="variable">collection</span>.<span class="variable">length</span>;Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 934–935why, one step back934 <span class="keyword">delete</span> <span class="variable">options</span>.<span class="variable">collection</span>;935 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">collectionLength</span> = <span class="variable">len</span>;Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 936why, one step back936 <span class="keyword">return</span> <span class="variable">collection</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">i</span>){Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
lines 937–945why, one step back937 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">firstInCollection</span> = <span class="variable">i</span> === <span class="number integer">0</span>;938 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">indexInCollection</span> = <span class="variable">i</span>;939 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">lastInCollection</span> = <span class="variable">i</span> === <span class="variable">len</span> - <span class="number integer">1</span>;940 <span class="variable">options</span>.<span class="variable">object</span> = <span class="variable">val</span>;941 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">partial</span>(<span class="variable">view</span>, <span class="variable">options</span>);942 }, <span class="this">this</span>).<span class="variable">join</span>(<span class="string">''</span>);943 } <span class="keyword">else</span> {944 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">object</span>) {945 <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">options</span>.<span class="variable">as</span> || <span class="variable">view</span>.<span class="variable">split</span>(<span class="string">'.'</span>)[<span class="number integer">0</span>];Regenerated docsTj Holowaychukbefore adoption09147a2
line 946why, one step back946 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">name</span> === <span class="string">'string'</span>) {Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 947why, one step back947 <span class="variable">options</span>.<span class="variable">locals</span>[<span class="variable">name</span>] = <span class="variable">options</span>.<span class="variable">object</span>;Regenerated docsTj Holowaychukbefore adoption09147a2
line 948why, one step back948 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">name</span> === <span class="variable">global</span>) {Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 949why, one step back949 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">options</span>.<span class="variable">locals</span>, <span class="variable">options</span>.<span class="variable">object</span>);Regenerated docsTj Holowaychukbefore adoption09147a2
line 950why, one step back950 } <span class="keyword">else</span> {Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 951why, one step back951 <span class="variable">options</span>.<span class="variable">context</span> = <span class="variable">options</span>.<span class="variable">object</span>;Regenerated docsTj Holowaychukbefore adoption09147a2
line 952why, one step back952 }Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701
line 953why, one step back953 }Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 954–964why, one step back954 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">render</span>(<span class="variable">view</span>, <span class="variable">options</span>);955 }956};</code></pre>957</td>958</tr>959<tr class="code">960<td class="docs">961<p>Render <code>view</code> with the given <code>options</code> and optional callback <code>fn</code>.962When a callback function is given a response will <em>not</em> be made963automatically, however otherwise a response of <em>200</em> and <em>text/html</em> is given.</p>964Updated docsTj Holowaychukbefore adoption09dabef
lines 965–969why, one step back965<h2>Options</h2>966967<p> Most engines accept one or more of the following options,968 both <em>haml</em> and <em>jade</em> accept all:</p>969More view docsTj Holowaychukbefore adoption1c8ff48
line 970why, one step back970<ul><li><code>context|scope</code> Template evaluation context (<code>this</code>)</li><li><code>locals</code> Object containing local variables</li><li><code>filename</code> Filename used for the <code>cache</code> option</li><li><code>cache</code> Cache intermediate JavaScript in memory</li><li><code>debug</code> Output debugging information</li></ul>Updated docsTj Holowaychukbefore adoption09dabef
line 971why, one step back971Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 972–973why, one step back972<h2></h2>973Regenerated api docsTj Holowaychukbefore adoption69baa6e
line 974why, one step back974<ul><li><p><strong>param</strong>: <em>String</em> view</p></li><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 975–978why, one step back975</td>976<td class="code">977<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">render</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">fn</span>){978 <span class="variable">options</span> = <span class="variable">options</span> || {};Regenerated docsTj Holowaychukbefore adoption09147a2
line 979why, one step back979 <span class="keyword">var</span> <span class="variable">defaultEngine</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'view engine'</span>);Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
line 980why, one step back980Regenerated docsTj Holowaychukbefore adoption09147a2
lines 981–985why, one step back981 <span class="comment">// Support "view engine" setting</span>982 <span class="keyword">if</span> (<span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">defaultEngine</span>) {983 <span class="variable">view</span> += <span class="string">'.'</span> + <span class="variable">defaultEngine</span>;984 }985Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 986–987why, one step back986 <span class="comment">// Defaults</span>987 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f
lines 988–989why, one step back988 <span class="variable">helpers</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">viewHelpers</span>,989 <span class="variable">dynamicHelpers</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">dynamicViewHelpers</span>,Regenerated docsTj Holowaychukbefore adoption09147a2
line 990why, one step back990 <span class="variable">root</span> = <span class="variable">viewRoot</span>(<span class="this">this</span>.<span class="variable">app</span>),Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 991–996why, one step back991 <span class="variable">ext</span> = <span class="variable">extname</span>(<span class="variable">view</span>),992 <span class="variable">partial</span> = <span class="variable">options</span>.<span class="variable">partial</span>,993 <span class="variable">layout</span> = <span class="variable">options</span>.<span class="variable">layout</span> === <span class="variable">undefined</span> ? <span class="variable">true</span> : <span class="variable">options</span>.<span class="variable">layout</span>,994 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>995 ? <span class="string">'layout'</span> + <span class="variable">ext</span>996 : <span class="variable">layout</span>;Updated docsTj Holowaychukbefore adoption09dabef
line 997why, one step back997Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 998–1002why, one step back998 <span class="comment">// Allow layout name without extension</span>999 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">layout</span> === <span class="string">'string'</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">layout</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {1000 <span class="variable">layout</span> += <span class="variable">ext</span>;1001 }1002In depth partial docsTj Holowaychukbefore adoption793943f
lines 1003–1005why, one step back1003 <span class="comment">// Normalize "context" to "scope"</span>1004 <span class="variable">options</span>.<span class="variable">scope</span> = <span class="variable">options</span>.<span class="variable">scope</span> || <span class="variable">options</span>.<span class="variable">context</span>;1005Updated docsTj Holowaychukbefore adoption09dabef
lines 1006–1009why, one step back1006 <span class="comment">// Auto-cache in production</span>1007 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'env'</span>) === <span class="string">'production'</span>) {1008 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;1009 }Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1010–1027why, one step back10101011 <span class="comment">// Partials support</span>1012 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">partial</span>) {1013 <span class="variable">root</span> += <span class="string">'/partials'</span>;1014 }10151016 <span class="comment">// View path</span>1017 <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">root</span> + <span class="string">'/'</span> + <span class="variable">view</span>;10181019 <span class="comment">// Send response</span>1020 <span class="keyword">function</span> <span class="variable">send</span>(<span class="variable">str</span>) {1021 <span class="variable">self</span>.<span class="variable">writeHead</span>(<span class="number integer">200</span>, {1022 <span class="string">'Content-Type'</span>: <span class="string">'text/html'</span>,1023 <span class="string">'Content-Length'</span>: <span class="variable">str</span>.<span class="variable">length</span>1024 });1025 <span class="variable">self</span>.<span class="variable">end</span>(<span class="variable">str</span>);1026 }1027Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1028–1030why, one step back1028 <span class="comment">// Pass filename to the engine and view</span>1029 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};1030 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">__filename</span> = <span class="variable">options</span>.<span class="variable">filename</span> = <span class="variable">path</span>;Added app.helpers() docsTj Holowaychukbefore adoption7eb088b
lines 1031–1040why, one step back10311032 <span class="comment">// Dynamic helper support</span>1033 <span class="keyword">var</span> <span class="variable">keys</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">dynamicHelpers</span>);1034 <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">keys</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {1035 <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>],1036 <span class="variable">val</span> = <span class="variable">dynamicHelpers</span>[<span class="variable">key</span>];1037 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">val</span> === <span class="string">'function'</span>) {1038 <span class="variable">helpers</span>[<span class="variable">key</span>] = <span class="variable">val</span>.<span class="variable">call</span>(<span class="this">this</span>.<span class="variable">app</span>, <span class="this">this</span>.<span class="variable">req</span>, <span class="this">this</span>, <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">path</span>);1039 }1040 }Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1041–1045why, one step back10411042 <span class="comment">// Always expose partial() as a local</span>1043 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>){1044 <span class="keyword">return</span> <span class="variable">self</span>.<span class="variable">partial</span>.<span class="variable">call</span>(<span class="variable">self</span>, <span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>);1045 };Regenerated docsTj Holowaychukbefore adoption60cfd56
lines 1046–1047why, one step back1046 1047 <span class="comment">// Merge view helpers</span>Started migration docsTj Holowaychukbefore adoption9e68a5b
line 1048why, one step back1048 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">__proto__</span> = <span class="variable">helpers</span>;Regenerated docsTj Holowaychukbefore adoption09147a2
line 1049why, one step back1049Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1050–1057why, one step back1050 <span class="keyword">function</span> <span class="variable">error</span>(<span class="variable">err</span>) {1051 <span class="keyword">if</span> (<span class="variable">fn</span>) {1052 <span class="variable">fn</span>(<span class="variable">err</span>);1053 } <span class="keyword">else</span> {1054 <span class="keyword">throw</span> <span class="variable">err</span>;1055 }1056 }1057Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1058–1059why, one step back1058 <span class="comment">// Cache contents</span>1059 <span class="keyword">try</span> {Added test-cov docs to contrib guideTj Holowaychukbefore adoption1fb73e2
line 1060why, one step back1060 <span class="keyword">var</span> <span class="variable">str</span> = <span class="variable">viewCache</span>[<span class="variable">path</span>] || <span class="variable">cacheViewSync</span>(<span class="variable">path</span>);Regenerated docsTj Holowaychukbefore adoption09147a2
lines 1061–1088why, one step back1061 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1062 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1063 }10641065 <span class="comment">// Cache template engine exports</span>1066 <span class="keyword">var</span> <span class="variable">engine</span> = <span class="variable">cache</span>[<span class="variable">ext</span>] || (<span class="variable">cache</span>[<span class="variable">ext</span>] = <span class="variable">require</span>(<span class="variable">ext</span>.<span class="variable">substr</span>(<span class="number integer">1</span>)));10671068 <span class="comment">// Attempt render</span>1069 <span class="keyword">try</span> {1070 <span class="keyword">var</span> <span class="variable">str</span> = <span class="variable">engine</span>.<span class="variable">render</span>(<span class="variable">str</span>, <span class="variable">options</span>);1071 } <span class="keyword">catch</span> (<span class="variable">err</span>) {1072 <span class="keyword">return</span> <span class="variable">error</span>(<span class="variable">err</span>);1073 }10741075 <span class="comment">// Layout support</span>1076 <span class="keyword">if</span> (<span class="variable">layout</span>) {1077 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;1078 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">body</span> = <span class="variable">str</span>;1079 <span class="variable">self</span>.<span class="variable">render</span>(<span class="variable">layout</span>, <span class="variable">options</span>);1080 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">partial</span>) {1081 <span class="keyword">return</span> <span class="variable">str</span>;1082 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {1083 <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">str</span>);1084 } <span class="keyword">else</span> {1085 <span class="variable">send</span>(<span class="variable">str</span>);1086 }1087};1088</code></pre>Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 1089–1091why, one step back1089</td>1090</tr> </body>1091</html></tbody></table>