Skip to content
Myr

Regenerated api docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 0fce93b · Browse files · 1 file+142 added−362 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+142 added−362 removed

  • other:+142 added−362 removed

1 file+142 added−362 removed

modified:docs/api.html+142 added-362 removed
1<html>2 <head>3 <title>Express</title>4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>5 <style>body {6 margin: 0;7 padding: 0;8 font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
12 unmodified lines
21h1, h2, h3 {22 margin: 0;23 padding: 0;24}24ul#menu {25 opacity: 0;26 position: fixed;27 top: 0;28 right: 0;29 list-style: none;30 margin: 0;31 padding: 10px 2px;32 text-align: right;33 background: rgba(255,255,255,0.7);34 -webkit-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);35 -moz-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);36 -webkit-border-bottom-left-radius: 5px;37 -moz-border-bottom-left-radius: 5px;38 -webkit-transition-properties: opacity;39 -webkit-transition-duration: 0.6s;40}41ul#menu:hover {42 opacity: 1;43}44ul#menu li {45 padding: 2px 10px;46 border-bottom: 1px solid #eee;47}48ul#menu li:hover {49 background: rgba(0,0,0,0.03);50}51ul#menu li:last-child {52 border-bottom: none;53}54ul#menu li a {55 text-decoration: none;56 font-size: 12px;57 color: rgba(0,0,0,0.5);58}59ul#menu li a strong {60 font-weight: normal;61 color: #252519;62}25table#source {26 width: 100%;27 border-collapse: collapse;28}
25 unmodified lines
54}55table#source tr.filename h2 {56 margin: 0;57 padding: 0;58 cursor: pointer;59}60table#source tr.code h1,61table#source tr.code h2,62table#source tr.code h3 {
22 unmodified lines
85table#source tr.code td:first-child pre {86 padding: 20px;87}88#ribbon {126 position: absolute;89 position: fixed;90 top: 0;91 right: 0;92}93code .string { color: #219161; }
1 unmodified line
95code .keyword { color: #954121; }96code .number { color: #19469D; }97code .comment { color: #bbb; }98code .this { color: #19469D; }</style>99 <script>100 $(function(){101 $('tr.code').hide();102 $('tr.filename').toggle(function(){103 $(this).nextUntil('.filename').fadeIn();104 }, function(){105 $(this).nextUntil('.filename').fadeOut();106 });107 });108 </script>109 </head>110 <body>138<ul id="menu"><li><a href="#lib/express/index.js">lib/express/<strong>index</strong></a></li>139<li><a href="#lib/express/request.js">lib/express/<strong>request</strong></a></li>140<li><a href="#lib/express/response.js">lib/express/<strong>response</strong></a></li>141<li><a href="#lib/express/server.js">lib/express/<strong>server</strong></a></li>142<li><a href="#lib/express/utils.js">lib/express/<strong>utils</strong></a></li>143<li><a href="#lib/express/view.js">lib/express/<strong>view</strong></a></li></ul><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">index</h2></td><td>lib/express/index.js</td></tr><tr class="code">111<table id="source"><tbody><tr><td><h1>Express</h1><p>High performance web framework for <a href="http://nodejs.org">node</a>.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/express/index.js"><a href="#">index</a></h2></td><td>lib/express/index.js</td></tr><tr class="code">112<td class="docs">145<p>Framework version.</p>113<p>Framework version.114 </p>115</td>116<td class="code">117<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.14.0'</span>;</code></pre>118</td>119</tr>120<tr class="code">121<td class="docs">153<p>Module dependencies.</p>122<p>Module dependencies.123 </p>124</td>125<td class="code">126<pre><code><span class="keyword">var</span> <span class="class">Server</span> = <span class="variable">require</span>(<span class="string">'./server'</span>);</code></pre>127</td>
3 unmodified lines
131<p>Shortcut for <code>new Server(...)</code>.</p>132133<h2></h2>134165<ul>166<li><p><strong>param</strong>: <em>Function</em> &hellip;</p></li>167<li><p><strong>return</strong>: <em>Server</em></p></li>168<li><p><strong>api</strong>: <em>public</em></p></li>169</ul>170135<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>136</td>137<td class="code">138<pre><code><span class="variable">exports</span>.<span class="variable">createServer</span> = <span class="keyword">function</span>(){139 <span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Server</span>(<span class="class">Array</span>.<span class="variable">prototype</span>.<span class="variable">slice</span>.<span class="variable">call</span>(<span class="variable">arguments</span>));
1 unmodified line
141</td>142</tr>143<tr class="code">144<td class="docs">180<p>View extensions.</p>145<p>View extensions.146 </p>147</td>148<td class="code">149<pre><code><span class="variable">require</span>(<span class="string">'./view'</span>);150<span class="variable">require</span>(<span class="string">'./request'</span>);151<span class="variable">require</span>(<span class="string">'./response'</span>);152</code></pre>153</td>188</tr><tr class="filename"><td><h2 id="lib/express/request.js">request</h2></td><td>lib/express/request.js</td></tr><tr class="code">154</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">155<td class="docs">190<p>Module dependencies.</p>156<p>Parse mini markdown implementation.157The following conversions are supported,158primarily for the "flash" middleware:</p>159160<p> <em>foo</em> or <em>foo</em> become &lt;em&gt;foo&lt;/em&gt;161 <strong>foo</strong> or <strong>foo</strong> become &lt;strong&gt;foo&lt;/strong&gt;162 <a href="B">A</a> becomes &lt;a href="B"&gt;A&lt;/a&gt;</p>163164<h2></h2>165166<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>167</td>168<td class="code">169<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){170 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)171 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)172 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)173 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'&lt;a href=&quot;$2&quot;&gt;$1&lt;/a&gt;'</span>);174};</code></pre>175</td>176</tr>177<tr class="code">178<td class="docs">179<p>Escape special characters in the given string of html.</p>180181<h2></h2>182183<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>184</td>185<td class="code">186<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {187 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)188 .<span class="variable">replace</span>(<span class="regexp">/&amp;/g</span>, <span class="string">'&amp;'</span>)189 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)190 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)191 .<span class="variable">replace</span>(<span class="regexp">/&gt;/g</span>, <span class="string">'&gt;'</span>);192};</code></pre>193</td>194</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">195<td class="docs">196<p>Module dependencies.197 </p>198</td>199<td class="code">200<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),201 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'./utils'</span>),202 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>;</code></pre>203</td>
13 unmodified lines
217req.header('Accept');218// =&gt; undefined219220req.header('Accept', 'text/html');214// =&gt; "text/html"215</code></pre>221// =&gt; "text/html"</code></pre>222223<h2></h2>224219<ul>220<li><p><strong>param</strong>: <em>String</em> name</p></li>221<li><p><strong>param</strong>: <em>String</em> defaultValue</p></li>222<li><p><strong>return</strong>: <em>String</em></p></li>223<li><p><strong>api</strong>: <em>public</em></p></li>224</ul>225225<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>226</td>227<td class="code">228<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>){229 <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>;
5 unmodified lines
235<p>Check if the <em>Accept</em> header is present, and includes the given <code>type</code>.</p>236237<p>When the <em>Accept</em> header is not present <code>true</code> is returned. Otherwise238the given <code>type</code> is matched by an exact match, and then subtypes. You239may pass the subtype such as &ldquo;html&rdquo; which is then converted internally240to &ldquo;text/html&rdquo; using the mime lookup table.</p>239may pass the subtype such as "html" which is then converted internally240to "text/html" using the mime lookup table.</p>241242<h2>Examples</h2>243244<pre><code>// Accept: text/html
8 unmodified lines
253// =&gt; true254255req.accepts('image/png');256req.accepts('png');257// =&gt; false258</code></pre>257// =&gt; false</code></pre>258259<h2></h2>260262<ul>263<li><p><strong>param</strong>: <em>String</em> type</p></li>264<li><p><strong>return</strong>: <em>Boolean</em></p></li>265<li><p><strong>api</strong>: <em>public</em></p></li>266</ul>267261<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>262</td>263<td class="code">264<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>){265 <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>);
1 unmodified line
267</td>268</tr>269<tr class="code">270<td class="docs">277<p>&lsquo;) {</p>278279<pre><code> return true;280} else if (type) {281 // Allow "html" vs "text/html" etc282 if (type.indexOf('/') &lt; 0) {283 type = mime.types['.' + type];284 }285 // Check if we have a direct match286 if (accept.indexOf(type) &gt;= 0) {271<p>') {272 return true;273 } else if (type) {274 // Allow "html" vs "text/html" etc275 if (type.indexOf('/') &lt; 0) {276 type = mime.types['.' + type];277 }278 // Check if we have a direct match279 if (accept.indexOf(type) &gt;= 0) {280 return true;288 // Check if we have type/*281 // Check if we have type/<em>282 } else {283 type = type.split('/')[0] + '/</em>';284 return accept.indexOf(type) &gt;= 0;285 }286 } else {290 type = type.split('/')[0] + '/*';291 return accept.indexOf(type) &gt;= 0;287 return false;288 }293} else {294 return false;295}296</code></pre>289};</p>290298<p>};</p>299291<p>/**292Return the value of param <code>name</code> when present.</p>293303<ul>304<li>Checks route placeholders, ex: <em>/user/:id</em></li>305<li>Checks query string params, ex: ?id=12</li>306<li>Checks urlencoded body params, ex: id=12</li>307</ul>294<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>295309296<p>To utilize urlencoded request bodies, <code>req.body</code>297should be an object. This can be done by using298the <code>connect.bodyDecoder</code> middleware.</p>299300<h2></h2>301316<ul>317<li><p><strong>param</strong>: <em>String</em> name</p></li>318<li><p><strong>return</strong>: <em>String</em></p></li>319<li><p><strong>api</strong>: <em>public</em></p></li>320</ul>321302<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>303</td>304<td class="code">305<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>){306 <span class="comment">// Route params like /user/:id</span>
28 unmodified lines
335 req.flash('info');336 // =&gt; []337338 req.flash();358 // =&gt; { error: ['email delivery failed'], info: [] }359</code></pre>339 // =&gt; { error: ['email delivery failed'], info: [] }</code></pre>340341<h2></h2>342363<ul>364<li><p><strong>param</strong>: <em>String</em> type</p></li>365<li><p><strong>param</strong>: <em>String</em> msg</p></li>366<li><p><strong>return</strong>: <em>Array | Object | Number</em></p></li>367<li><p><strong>api</strong>: <em>public</em></p></li>368</ul>369343<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>344</td>345<td class="code">346<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>){347 <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> || {};
22 unmodified lines
370<p>Check if the request was an <em>XMLHttpRequest</em>.</p>371372<h2></h2>373400<ul>401<li><p><strong>return</strong>: <em>Boolean</em></p></li>402<li><p><strong>api</strong>: <em>public</em></p></li>403</ul>404374<ul><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>375</td>376<td class="code">377<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>);378<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>379</td>410</tr><tr class="filename"><td><h2 id="lib/express/response.js">response</h2></td><td>lib/express/response.js</td></tr><tr class="code">380</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">381<td class="docs">412<p>Module dependencies.</p>382<p>Module dependencies.383 </p>384</td>385<td class="code">386<pre><code><span class="keyword">var</span> <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>),387 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),
13 unmodified lines
401res.send({ some: 'json' });402res.send('&lt;p&gt;some html&lt;/p&gt;');403res.send('Sorry, cant find that', 404);404res.send('text', { 'Content-Type': 'text/plain' }, 201);434res.send(404);435</code></pre>405res.send(404);</code></pre>406407<h2></h2>408439<ul>440<li><p><strong>param</strong>: <em>String | Object | Number | Buffer</em> body or status</p></li>441<li><p><strong>param</strong>: <em>Object | Number</em> headers or status</p></li>442<li><p><strong>param</strong>: <em>Number</em> status</p></li>443<li><p><strong>return</strong>: <em>ServerResponse</em></p></li>444<li><p><strong>api</strong>: <em>public</em></p></li>445</ul>446409<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>410</td>411<td class="code">412<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>){413 <span class="comment">// Allow status as second arg</span>
55 unmodified lines
469response header, and responds with 404 / 500 appropriately.</p>470471<h2></h2>472510<ul>511<li><p><strong>param</strong>: <em>String</em> file</p></li>512<li><p><strong>api</strong>: <em>public</em></p></li>513</ul>514473<ul><li><p><strong>param</strong>: <em>String</em> file</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>474</td>475<td class="code">476<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>){477 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;
17 unmodified lines
495<h2>Examples</h2>496497<pre><code>var filename = 'path/to/image.png';498res.contentType(filename);540// res.headers['Content-Type'] is now "image/png"541</code></pre>499// res.headers['Content-Type'] is now "image/png"</code></pre>500501<h2></h2>502545<ul>546<li><p><strong>param</strong>: <em>String</em> type</p></li>547<li><p><strong>return</strong>: <em>String</em> the resolved mime type</p></li>548<li><p><strong>api</strong>: <em>public</em></p></li>549</ul>550503<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>504</td>505<td class="code">506<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>){507 <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>));
5 unmodified lines
513<p>Set <em>Content-Disposition</em> header to <em>attachment</em> with optional <code>filename</code>.</p>514515<h2></h2>516564<ul>565<li><p><strong>param</strong>: <em>String</em> filename</p></li>566<li><p><strong>return</strong>: <em>ServerResponse</em></p></li>567<li><p><strong>api</strong>: <em>public</em></p></li>568</ul>569517<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>518</td>519<td class="code">520<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>){521 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Disposition'</span>, <span class="variable">filename</span>
8 unmodified lines
530<p>Transfer the given <code>file</code> with optional <code>filename</code> as an attachment.</p>531532<h2></h2>533586<ul>587<li><p><strong>param</strong>: <em>String</em> file</p></li>588<li><p><strong>param</strong>: <em>String</em> filename</p></li>589<li><p><strong>return</strong>: <em>Type</em></p></li>590<li><p><strong>api</strong>: <em>public</em></p></li>591</ul>592534<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>535</td>536<td class="code">537<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>){538 <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>);
5 unmodified lines
544<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>545546<h2></h2>547606<ul>607<li><p><strong>param</strong>: <em>String</em> name</p></li>608<li><p><strong>param</strong>: <em>String</em> val</p></li>609<li><p><strong>return</strong>: <em>String</em></p></li>610<li><p><strong>api</strong>: <em>public</em></p></li>611</ul>612548<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>549</td>550<td class="code">551<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>){552 <span class="keyword">return</span> <span class="variable">val</span> === <span class="variable">undefined</span>
7 unmodified lines
560<p>Redirect to the given <code>url</code> with optional response <code>status</code>561defauling to 302.</p>562563<p>The given <code>url</code> can also be the name of a mapped url, for628example by default express supports &ldquo;back&rdquo; which redirects629to the <em>Referrer</em> or <em>Referer</em> headers or the application&rsquo;s630&ldquo;home&rdquo; setting. Express also supports &ldquo;home&rdquo; out of the box,564example by default express supports "back" which redirects565to the <em>Referrer</em> or <em>Referer</em> headers or the application's566"home" setting. Express also supports "home" out of the box,567which can be set via <code>app.set('home', '/blog');</code>, and defaults632to &lsquo;/&rsquo;.</p>568to '/'.</p>569570<h2>Redirect Mapping</h2>571572<p> To extend the redirect mapping capabilities that Express provides,573 we may use the <code>app.redirect()</code> method:</p>574639<pre><code>app.redirect('google', 'http://google.com');640</code></pre>575<pre><code>app.redirect('google', 'http://google.com');</code></pre>576577<p> Now in a route we may call:</p>578644<pre><code>res.redirect('google');645</code></pre>579<pre><code>res.redirect('google');</code></pre>580581<p> We may also map dynamic redirects:</p>582583<pre><code> app.redirect('comments', function(req, res, params){584 return '/post/' + params.id + '/comments';651 });652</code></pre>585 });</code></pre>586587<p> So now we may do the following, and the redirect will dynamically adjust to588 the context of the request. If we called this route with <em>GET /post/12</em> our589 redirect <em>Location</em> would be <em>/post/12/comments</em>.</p>590591<pre><code> app.get('/post/:id', function(req, res){592 res.redirect('comments');660 });661</code></pre>593 });</code></pre>594595<h2></h2>596665<ul>666<li><p><strong>param</strong>: <em>String</em> url</p></li>667<li><p><strong>param</strong>: <em>Number</em> code</p></li>668<li><p><strong>api</strong>: <em>public</em></p></li>669</ul>670597<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>598</td>599<td class="code">600<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>){601 <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>;
17 unmodified lines
619 <span class="this">this</span>.<span class="variable">end</span>();620};621</code></pre>622</td>696</tr><tr class="filename"><td><h2 id="lib/express/server.js">server</h2></td><td>lib/express/server.js</td></tr><tr class="code">623</tr><tr class="filename"><td><h2 id="lib/express/server.js"><a href="#">server</a></h2></td><td>lib/express/server.js</td></tr><tr class="code">624<td class="docs">698<p>Module dependencies.</p>625<p>Module dependencies.626 </p>627</td>628<td class="code">629<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),630 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),
8 unmodified lines
639<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>640641<h2></h2>642715<ul>716<li><p><strong>param</strong>: <em>Array</em> middleware</p></li>717<li><p><strong>api</strong>: <em>public</em></p></li>718</ul>719643<ul><li><p><strong>param</strong>: <em>Array</em> middleware</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>644</td>645<td class="code">646<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>){647 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;
27 unmodified lines
675</td>676</tr>677<tr class="code">678<td class="docs">755<p>Inherit from <code>connect.Server</code>.</p>679<p>Inherit from <code>connect.Server</code>.680 </p>681</td>682<td class="code">683<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>684</td>
3 unmodified lines
688<p>Listen on the given <code>port</code> after running configuration blocks.</p>689690<h2></h2>691767<ul>768<li><p><strong>param</strong>: <em>Number</em> port</p></li>769<li><p><strong>api</strong>: <em>public</em></p></li>770</ul>771692<ul><li><p><strong>param</strong>: <em>Number</em> port</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">listen</span> = <span class="keyword">function</span>(<span class="variable">port</span>){696 <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>);
3 unmodified lines
700 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {701 <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>));702 }703783 <span class="comment">// Custom exception handler</span>784 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">errorHandler</span>) {785 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</span>, <span class="this">this</span>.<span class="variable">errorHandler</span>);786 }787 704 <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>);705};</code></pre>706</td>707</tr>
2 unmodified lines
710<p>Run config callbacks for the given environment(s);</p>711712<h2></h2>713798<ul>799<li><p><strong>param</strong>: <em>String</em> env &hellip;</p></li>800<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>801<li><p><strong>api</strong>: <em>public</em></p></li>802</ul>803714<ul><li><p><strong>param</strong>: <em>String</em> env ...</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>715</td>716<td class="code">717<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">runConfig</span> = <span class="keyword">function</span>(){718 <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">arguments</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>) {
14 unmodified lines
733<p>Assign a custom exception handler callback <code>fn</code>.</p>734735<h2></h2>736826<ul>827<li><p><strong>param</strong>: <em>Function</em> fn</p></li>828<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>829<li><p><strong>api</strong>: <em>public</em></p></li>830</ul>831737<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>738</td>739<td class="code">740<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>){835 <span class="this">this</span>.<span class="variable">errorHandler</span> = <span class="variable">fn</span>;741 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</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>){742 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);743 });744 <span class="keyword">return</span> <span class="this">this</span>;745};</code></pre>746</td>747</tr>748<tr class="code">749<td class="docs">842<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>&rsquo;s value.</p>750<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>751752<h2></h2>753846<ul>847<li><p><strong>param</strong>: <em>String</em> setting</p></li>848<li><p><strong>param</strong>: <em>String</em> val</p></li>849<li><p><strong>return</strong>: <em>Server | Mixed</em> for chaining, or the setting value</p></li>850<li><p><strong>api</strong>: <em>public</em></p></li>851</ul>852754<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>755</td>756<td class="code">757<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>){758 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {
10 unmodified lines
769<p>Enable <code>setting</code>.</p>770771<h2></h2>772871<ul>872<li><p><strong>param</strong>: <em>String</em> setting</p></li>873<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>874<li><p><strong>api</strong>: <em>public</em></p></li>875</ul>876773<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>774</td>775<td class="code">776<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>){777 <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>);
5 unmodified lines
783<p>Disable <code>setting</code>.</p>784785<h2></h2>786890<ul>891<li><p><strong>param</strong>: <em>String</em> setting</p></li>892<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>893<li><p><strong>api</strong>: <em>public</em></p></li>894</ul>895787<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>788</td>789<td class="code">790<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>){791 <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>);
5 unmodified lines
797<p>Redirect <code>key</code> to <code>url</code>.</p>798799<h2></h2>800909<ul>910<li><p><strong>param</strong>: <em>String</em> key</p></li>911<li><p><strong>param</strong>: <em>String</em> url</p></li>912<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>913<li><p><strong>api</strong>: <em>public</em></p></li>914</ul>915801<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>802</td>803<td class="code">804<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>){805 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;
6 unmodified lines
812<p>Disable <code>setting</code>.</p>813814<h2></h2>815930<ul>931<li><p><strong>param</strong>: <em>String</em> setting</p></li>932<li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>933<li><p><strong>api</strong>: <em>public</em></p></li>934</ul>935816<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>817</td>818<td class="code">819<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>){820 <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>;
11 unmodified lines
832 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;833})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);834</code></pre>835</td>955</tr><tr class="filename"><td><h2 id="lib/express/utils.js">utils</h2></td><td>lib/express/utils.js</td></tr><tr class="code">836</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">837<td class="docs">957<p>Parse mini markdown implementation.958The following conversions are supported,959primarily for the &ldquo;flash&rdquo; middleware:</p>960961<p> <em>foo</em> or <em>foo</em> become <em>foo</em>962 <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>963 <a href="B">A</a> becomes <a href="B">A</a></p>964965<h2></h2>966967<ul>968<li><p><strong>param</strong>: <em>String</em> str</p></li>969<li><p><strong>return</strong>: <em>String</em></p></li>970<li><p><strong>api</strong>: <em>public</em></p></li>971</ul>972838<p>Module dependencies.839 </p>840</td>841<td class="code">975<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){976 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)977 .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'&lt;strong&gt;$2&lt;/strong&gt;'</span>)978 .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'&lt;em&gt;$2&lt;/em&gt;'</span>)979 .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'&lt;a href=&quot;$2&quot;&gt;$1&lt;/a&gt;'</span>);980};</code></pre>981</td>982</tr>983<tr class="code">984<td class="docs">985<p>Escape special characters in the given string of html.</p>986987<h2></h2>988989<ul>990<li><p><strong>param</strong>: <em>String</em> html</p></li>991<li><p><strong>return</strong>: <em>String</em></p></li>992<li><p><strong>api</strong>: <em>public</em></p></li>993</ul>994995</td>996<td class="code">997<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {998 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)999 .<span class="variable">replace</span>(<span class="regexp">/&amp;/g</span>, <span class="string">'&amp;'</span>)1000 .<span class="variable">replace</span>(<span class="regexp">/&quot;/g</span>, <span class="string">'&quot;'</span>)1001 .<span class="variable">replace</span>(<span class="regexp">/&lt;/g</span>, <span class="string">'&lt;'</span>)1002 .<span class="variable">replace</span>(<span class="regexp">/&gt;/g</span>, <span class="string">'&gt;'</span>);1003};</code></pre>1004</td>1005</tr><tr class="filename"><td><h2 id="lib/express/view.js">view</h2></td><td>lib/express/view.js</td></tr><tr class="code">1006<td class="docs">1007<p>Module dependencies.</p>1008</td>1009<td class="code">842<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>,843 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,844 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),845 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),
6 unmodified lines
852<p>Cache supported template engine exports to853increase performance by lowering the number854of calls to <code>require()</code>.</p>8551024<ul>1025<li><strong>type</strong>: <em>Object</em></li>1026</ul>1027856<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>857</td>858<td class="code">859<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = {};</code></pre>860</td>
1 unmodified line
862<tr class="code">863<td class="docs">864<p>Cache view contents to prevent I/O hits.</p>8651037<ul>1038<li><strong>type</strong>: <em>Object</em></li>1039</ul>1040866<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>867</td>868<td class="code">869<pre><code><span class="keyword">var</span> <span class="variable">viewCache</span> = {};</code></pre>870</td>
1 unmodified line
872<tr class="code">873<td class="docs">874<p>Clear the view cache.</p>8751050<ul>1051<li><strong>api</strong>: <em>public</em></li>1052</ul>1053876<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>877</td>878<td class="code">879<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){880 <span class="variable">viewCache</span> = {};
1 unmodified line
882</td>883</tr>884<tr class="code">885<td class="docs">1063<p>View helpers merged with each render&rsquo;s locals.</p>886<p>View helpers merged with each render's locals.</p>8871065<ul>1066<li><strong>type</strong>: <em>Object</em></li>1067</ul>1068888<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>889</td>890<td class="code">891<pre><code><span class="keyword">var</span> <span class="variable">helpers</span> = <span class="variable">exports</span>.<span class="variable">helpers</span> = {};</code></pre>892</td>
3 unmodified lines
896<p>Render <code>view</code> partial with the given <code>options</code>.</p>897898<h2>Options</h2>8991080<ul>1081<li><p><code>as</code> Variable name for each <code>collection</code> value, defaults to the view name.</p>900<ul><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. 901For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li></ul>9021083<ul>1084<li>as: &lsquo;something&rsquo; will add the <code>something</code> local variable</li>1085<li>as: this will use the collection value as the template context</li>1086<li>as: global will merge the collection value&rsquo;s properties with <code>locals</code></li>1087</ul>1088</li>1089<li><p><code>collection</code> Array of objects, the name is derived from the view name itself.1090For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li>1091</ul>10921093903<h2></h2>9041096<ul>1097<li><p><strong>param</strong>: <em>String</em> view</p></li>1098<li><p><strong>param</strong>: <em>Object | Array</em> options or collection</p></li>1099<li><p><strong>return</strong>: <em>String</em></p></li>1100<li><p><strong>api</strong>: <em>public</em></p></li>1101</ul>1102 %905<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>906</td>907<td class="code">908<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>){909 <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>) {
40 unmodified lines
950951<p> Most engines accept one or more of the following options,952 both <em>haml</em> and <em>jade</em> accept all:</p>9531151<ul>1152<li><code>context</code> Template evaluation context (<code>this</code>)</li>1153<li><code>locals</code> Object containing local variables</li>1154<li><code>filename</code> Filename used for the <code>cache</code> option</li>1155<li><code>cache</code> Cache intermediate JavaScript in memory</li>1156<li><code>debug</code> Output debugging information</li>1157</ul>954<ul><li><code>context</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>9551159956<h2></h2>9571162<ul>1163<li><p><strong>param</strong>: <em>String</em> view</p></li>1164<li><p><strong>param</strong>: <em>Object</em> options</p></li>1165<li><p><strong>param</strong>: <em>Function</em> fn</p></li>1166<li><p><strong>api</strong>: <em>public</em></p></li>1167</ul>1168 res.redirect('comments');1169 });11701171## 1172 - **param**: _String_ url11731174 - **param**: _Number_ code11751176 - **api**: _public_11771178 958<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>959</td>960<td class="code">961<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>){962 <span class="variable">options</span> = <span class="variable">options</span> || {};
93 unmodified lines