Added app.register() 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 9a8166d · Browse files · 8 files·+438 added−131 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+438 added−131 removed
- other:+438 added−131 removed
Provenance
- Commit
77e5d8e- Tree
c39b798- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
9a8166d
8 files changed+438 added−131 removed
modified:docs/api.html+169 added-76 removed
108 unmodified lines109 </head>110 <body>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">113+<p>Re-export connect auto-loaders.</p>114+115+<p>This prevents the need to <code>require('connect')</code> in order116+to access core middleware, so for example <code>express.logger()</code> instead117+of <code>require('connect').logger()</code>.118+ </p>119+</td>120+<td class="code">121+<pre><code><span class="keyword">var</span> <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="variable">require</span>(<span class="string">'connect'</span>).<span class="variable">middleware</span>;</code></pre>122+</td>123+</tr>124+<tr class="code">125+<td class="docs">126 <p>Framework version.127 </p>128 </td>129 <td class="code">307 unmodified lines437 </td>438 </tr>439 <tr class="code">440 <td class="docs">428-<p>Transfer the given <code>file</code>. Automatically sets the <em>Content-Type</em>429-response header, and responds with 404 / 500 appropriately.</p>441+<p>Transfer the file at the given <code>path</code>. Automatically sets 442+the <em>Content-Type</em> response header via <code>res.contentType()</code>. </p>443 444+<p>The given callback <code>fn</code> is invoked when an error occurs,445+passing it as the first argument, or when the file is transferred,446+passing the path as the second argument.</p>447+448 <h2></h2>449 433-<ul><li><p><strong>param</strong>: <em>String</em> file</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>450+<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>451 </td>452 <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>){453+<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">path</span>, <span class="variable">fn</span>){454 <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>){455+ <span class="variable">fs</span>.<span class="variable">readFile</span>(<span class="variable">path</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">buf</span>){456 <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>);457+ <span class="keyword">if</span> (<span class="variable">fn</span>) {458+ <span class="variable">fn</span>(<span class="variable">err</span>, <span class="variable">path</span>);459+ } <span class="keyword">else</span> {460+ <span class="variable">self</span>.<span class="variable">req</span>.<span class="variable">next</span>(<span class="variable">err</span>);461+ }462 } <span class="keyword">else</span> {444- <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">file</span>);463+ <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">path</span>);464 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">buf</span>);465+ <span class="variable">fn</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">path</span>);466 }467 });468 };</code></pre>469 </td>36 unmodified lines506 </td>507 </tr>508 <tr class="code">509 <td class="docs">490-<p>Transfer the given <code>file</code> with optional <code>filename</code> as an attachment.</p>510+<p>Transfer the file at the given <code>path</code>, with optional 511+<code>filename</code> as an attachment. Once transferred, or if an512+error occurs <code>fn</code> is called with the error and path.</p>513 514 <h2></h2>515 494-<ul><li><p><strong>param</strong>: <em>String</em> file</p></li><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>Type</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>516+<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Type</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>517 </td>518 <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>);519+<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">path</span>, <span class="variable">filename</span>, <span class="variable">fn</span>){520+ <span class="this">this</span>.<span class="variable">attachment</span>(<span class="variable">filename</span> || <span class="variable">path</span>).<span class="variable">sendfile</span>(<span class="variable">path</span>, <span class="variable">fn</span>);521 };</code></pre>522 </td>523 </tr>524 <tr class="code">67 unmodified lines592 <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>;593 594 <span class="comment">// Attempt mapped redirect</span>595 <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>)596+ ? <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>)597 : <span class="variable">map</span>[<span class="variable">url</span>];598 599 <span class="comment">// Perform redirect</span>600 <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> });601 <span class="this">this</span>.<span class="variable">end</span>();602 };603 </code></pre>604 </td>605+</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">606+<td class="docs">607+<p>Parse mini markdown implementation.608+The following conversions are supported,609+primarily for the "flash" middleware:</p>610+611+<p> <em>foo</em> or <em>foo</em> become <em>foo</em>612+ <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>613+ <a href="B">A</a> becomes <a href="B">A</a></p>614+615+<h2></h2>616+617+<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>618+</td>619+<td class="code">620+<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){621+ <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)622+ .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)623+ .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)624+ .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'<a href="$2">$1</a>'</span>);625+};</code></pre>626+</td>627+</tr>628+<tr class="code">629+<td class="docs">630+<p>Escape special characters in the given string of html.</p>631+632+<h2></h2>633+634+<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>635+</td>636+<td class="code">637+<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {638+ <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)639+ .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)640+ .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)641+ .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)642+ .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);643+};</code></pre>644+</td>645 </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">646 <td class="docs">647 <p>Module dependencies.648 </p>23 unmodified lines672 <span class="this">this</span>.<span class="variable">settings</span> = {};673 <span class="this">this</span>.<span class="variable">redirects</span> = {};674 <span class="this">this</span>.<span class="variable">viewHelpers</span> = {};675 <span class="this">this</span>.<span class="variable">dynamicViewHelpers</span> = {};676+ <span class="this">this</span>.<span class="variable">errorHandlers</span> = [];677 <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> || []);678 679 <span class="comment">// Default "home" to / </span>680 <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'home'</span>, <span class="string">'/'</span>);38 unmodified lines719 </td>720 </tr>721 <tr class="code">722 <td class="docs">723+<p>Stack error handler callbacks, then listen on the given724+<code>port</code> and <code>host</code>.</p>725+726+<h2></h2>727+728+<ul><li><p><strong>param</strong>: <em>Number | String</em> port</p></li><li><p><strong>param</strong>: <em>String</em> host</p></li><li><p><strong>return</strong>: <em>Type</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>729+</td>730+<td class="code">731+<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span> = <span class="keyword">function</span>(){732+ <span class="this">this</span>.<span class="variable">errorHandlers</span>.<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">fn</span>){733+ <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>){734+ <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);735+ });736+ }, <span class="this">this</span>);737+ <span class="variable">connect</span>.<span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">listen</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);738+};</code></pre>739+</td>740+</tr>741+<tr class="code">742+<td class="docs">743 <p>Proxy <code>connect.Server#use()</code> to apply settings to744 mounted applications.</p>745 746 <h2></h2>52 unmodified lines799 </td>800 </tr>801 <tr class="code">802 <td class="docs">803+<h2>See view.register.</h2>804+805+<h2></h2>806+807+<ul><li><p><strong>return</strong>: <em>Server</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>808+</td>809+<td class="code">810+<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">register</span> = <span class="keyword">function</span>(){811+ <span class="variable">view</span>.<span class="variable">register</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);812+ <span class="keyword">return</span> <span class="this">this</span>;813+};</code></pre>814+</td>815+</tr>816+<tr class="code">817+<td class="docs">818 <p>Register the given view helpers <code>obj</code>. This method819 can be called several times to apply additional helpers.</p>820 821 <h2></h2>24 unmodified lines846 </td>847 </tr>848 <tr class="code">849 <td class="docs">752-<p>Assign a custom exception handler callback <code>fn</code>.</p>850+<p>Assign a custom exception handler callback <code>fn</code>.851+These handlers are always <em>last</em> in the middleware stack.</p>852 853 <h2></h2>854 855 <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>856 </td>857 <td class="code">858 <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>){760- <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>){761- <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);762- });859+ <span class="this">this</span>.<span class="variable">errorHandlers</span>.<span class="variable">push</span>(<span class="variable">fn</span>);860 <span class="keyword">return</span> <span class="this">this</span>;861 };</code></pre>862 </td>863 </tr>91 unmodified lines955 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;956 })(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);957 </code></pre>958 </td>862-</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">863-<td class="docs">864-<p>Parse mini markdown implementation.865-The following conversions are supported,866-primarily for the "flash" middleware:</p>867-868-<p> <em>foo</em> or <em>foo</em> become <em>foo</em>869- <strong>foo</strong> or <strong>foo</strong> become <strong>foo</strong>870- <a href="B">A</a> becomes <a href="B">A</a></p>871-872-<h2></h2>873-874-<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>875-</td>876-<td class="code">877-<pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){878- <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)879- .<span class="variable">replace</span>(<span class="regexp">/(__|\*\*)(.*?)\1/g</span>, <span class="string">'<strong>$2</strong>'</span>)880- .<span class="variable">replace</span>(<span class="regexp">/(_|\*)(.*?)\1/g</span>, <span class="string">'<em>$2</em>'</span>)881- .<span class="variable">replace</span>(<span class="regexp">/\[([^\]]+)\]\(([^)]+)\)/g</span>, <span class="string">'<a href="$2">$1</a>'</span>);882-};</code></pre>883-</td>884-</tr>885-<tr class="code">886-<td class="docs">887-<p>Escape special characters in the given string of html.</p>888-889-<h2></h2>890-891-<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>892-</td>893-<td class="code">894-<pre><code><span class="variable">exports</span>.<span class="variable">htmlEscape</span> = <span class="keyword">function</span>(<span class="variable">html</span>) {895- <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">html</span>)896- .<span class="variable">replace</span>(<span class="regexp">/&/g</span>, <span class="string">'&'</span>)897- .<span class="variable">replace</span>(<span class="regexp">/"/g</span>, <span class="string">'"'</span>)898- .<span class="variable">replace</span>(<span class="regexp">/</g</span>, <span class="string">'<'</span>)899- .<span class="variable">replace</span>(<span class="regexp">/>/g</span>, <span class="string">'>'</span>);900-};</code></pre>901-</td>959 </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">960 <td class="docs">961 <p>Module dependencies.962 </p>30 unmodified lines993 </td>994 </tr>995 <tr class="code">996 <td class="docs">940-<p>Clear the view cache.</p>997+<p>Register the given template engine <code>exports</code>998+as <code>ext</code>. For example we may wish to map ".html"999+files to jade:</p>1000 942-<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>1001+<p> app.register('.html', require('jade'));</p>1002+1003+<p>This is also useful for libraries that may not1004+match extensions correctly. For example my haml.js1005+library is installed from npm as "hamljs" so instead1006+of layout.hamljs, we can register the engine as ".haml":</p>1007+1008+<p> app.register('.haml', require('haml-js'));</p>1009+1010+<p>For engines that do not comply with the Express1011+specification, we can also wrap their api this way.</p>1012+1013+<p> app.register('.foo', {1014+ render: function(str, options) {1015+ // perhaps their api is1016+ // foo.toHTML(str, options);1017+ }1018+ });</p>1019+1020+<h2></h2>1021+1022+<ul><li><p><strong>param</strong>: <em>String</em> ext</p></li><li><p><strong>param</strong>: <em>Object</em> obj</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>1023 </td>1024 <td class="code">945-<pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){946- <span class="variable">viewCache</span> = {};1025+<pre><code><span class="variable">exports</span>.<span class="variable">register</span> = <span class="keyword">function</span>(<span class="variable">ext</span>, <span class="variable">exports</span>) {1026+ <span class="variable">cache</span>[<span class="variable">ext</span>] = <span class="variable">exports</span>;1027 };</code></pre>1028 </td>1029 </tr>1030 <tr class="code">71 unmodified lines1102 <ul><li><code>context|scope</code> Template evaluation context (<code>this</code>)</li><li><code>locals</code> Object containing local variables</li><li><code>debug</code> Output debugging information</li></ul>1103 1104 <h2></h2>1105 1026-<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>1106+<ul><li><p><strong>param</strong>: <em>String</em> view</p></li><li><p><strong>param</strong>: <em>Object | Function</em> options or callback function</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>1107 </td>1108 <td class="code">1109 <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>){1030- <span class="variable">options</span> = <span class="variable">options</span> || {};1031- <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>);1110+ <span class="comment">// Support callback function as second arg</span>1111+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">options</span> === <span class="string">'function'</span>) {1112+ <span class="variable">fn</span> = <span class="variable">options</span>, <span class="variable">options</span> = {};1113+ }1114+ 1115+ <span class="keyword">var</span> <span class="variable">options</span> = <span class="variable">options</span> || {},1116+ <span class="variable">viewOptions</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'view options'</span>),1117+ <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>);1118 1119+ <span class="comment">// Mixin "view options"</span>1120+ <span class="keyword">if</span> (<span class="variable">viewOptions</span>) <span class="variable">options</span>.<span class="variable">__proto__</span> = <span class="variable">viewOptions</span>;1121+1122 <span class="comment">// Support "view engine" setting</span>1123 <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>) {1124 <span class="variable">view</span> += <span class="string">'.'</span> + <span class="variable">defaultEngine</span>;1125 }24 unmodified lines1150 }1151 1152 <span class="comment">// Partials support</span>1153 <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">partial</span>) {1065- <span class="variable">root</span> += <span class="string">'/partials'</span>;1154+ <span class="variable">root</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'partials'</span>)1155+ ? <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'partials'</span>)1156+ : <span class="variable">root</span> + <span class="string">'/partials'</span>;1157 }1158 1159 <span class="comment">// View path</span>1160 <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">view</span>[<span class="number integer">0</span>] === <span class="string">'/'</span>4 unmodified lines1165 <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};1166 <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>;1167 1168 <span class="comment">// Dynamic helper support</span>1169+ <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">dynamicHelpers</span> !== <span class="variable">false</span>) {1078- <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>);1079- <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>) {1080- <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>],1081- <span class="variable">val</span> = <span class="variable">dynamicHelpers</span>[<span class="variable">key</span>];1082- <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">val</span> === <span class="string">'function'</span>) {1083- <span class="variable">helpers</span>[<span class="variable">key</span>] = <span class="variable">val</span>.<span class="variable">call</span>(1084- <span class="this">this</span>.<span class="variable">app</span>, 1085- <span class="this">this</span>.<span class="variable">req</span>, 1086- <span class="this">this</span>, 1087- <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">path</span>);1170+ <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>);1171+ <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>) {1172+ <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>],1173+ <span class="variable">val</span> = <span class="variable">dynamicHelpers</span>[<span class="variable">key</span>];1174+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">val</span> === <span class="string">'function'</span>) {1175+ <span class="variable">helpers</span>[<span class="variable">key</span>] = <span class="variable">val</span>.<span class="variable">call</span>(1176+ <span class="this">this</span>.<span class="variable">app</span>, 1177+ <span class="this">this</span>.<span class="variable">req</span>, 1178+ <span class="this">this</span>);1179+ }1180 }1181 }1182 1183 <span class="comment">// Always expose partial() as a local</span>32 unmodified lines1216 <span class="comment">// Layout support</span>1217 <span class="keyword">if</span> (<span class="variable">layout</span>) {1218 <span class="variable">options</span>.<span class="variable">layout</span> = <span class="variable">false</span>;1219 <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">body</span> = <span class="variable">str</span>;1220+ <span class="variable">options</span>.<span class="variable">isLayout</span> = <span class="variable">true</span>;1221 <span class="variable">self</span>.<span class="variable">render</span>(<span class="variable">layout</span>, <span class="variable">options</span>, <span class="variable">fn</span>);1222 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">partial</span>) {1223 <span class="keyword">return</span> <span class="variable">str</span>;1224 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {9 unmodified linesmodified:docs/guide.1+137 added-14 removed
72 unmodified lines73 .74 .nf75 76 app\.configure(function(){77- app\.use(connect\.methodOverride());78- app\.use(connect\.bodyDecoder());77+ app\.use(express\.methodOverride());78+ app\.use(express\.bodyDecoder());79 app\.use(app\.router);80- app\.use(connect\.staticProvider(__dirname + \'/public\'));80+ app\.use(express\.staticProvider(__dirname + \'/public\'));81 });82 83 app\.configure(\'development\', function(){84- app\.use(connect\.errorHandler({ dumpExceptions: true, showStack: true }));84+ app\.use(express\.errorHandler({ dumpExceptions: true, showStack: true }));85 });86 87 app\.configure(\'production\', function(){88- app\.use(connect\.errorHandler());88+ app\.use(express\.errorHandler());89 });90 .91 .fi92 .49 unmodified lines142 .143 .IP "\(bu" 4144 \fIview engine\fR Default view engine name for views rendered without extensions145 .146+.IP "\(bu" 4147+\fIview options\fR An object specifying global view options148+.149+.IP "\(bu" 4150+\fIpartials\fR Root view partials directory defaulting to \fIviews\fR/partials\.151+.152 .IP "" 0153 .154 .SS "Routing"155 Express utilizes the HTTP verbs to provide a meaningful, expressive routing API\. For example we may want to render a user\'s account for the path \fI/user/12\fR, this can be done by defining the route below\. The values associated to the named placeholders are available as \fBreq\.params\fR\.127 unmodified lines283 .IP "" 4284 .285 .nf286 281-var connect = require(\'connect\'),282- express = require(\'express\');287+var express = require(\'express\');288 289 var app = express\.createServer(285- connect\.logger(),286- connect\.bodyDecoder()290+ express\.logger(),291+ express\.bodyDecoder()292 );293 .294 .fi295 .5 unmodified lines301 .IP "" 4302 .303 .nf304 300-app\.use(connect\.logger({ format: \':method :uri\' }));305+app\.use(express\.logger({ format: \':method :uri\' }));306 .307 .fi308 .309 .IP "" 0310 .311+.P312+Typically with connect middleware you would \fIrequire(\'connect\')\fR like so:313+.314+.IP "" 4315+.316+.nf317+318+var connect = require(\'connect\');319+app\.use(connect\.logger());320+.321+.fi322+.323+.IP "" 0324+.325+.P326+This is somewhat annoying, so express re\-exports these middleware properties, however they are \fIidentical\fR:327+.328+.IP "" 4329+.330+.nf331+332+app\.use(express\.logger());333+.334+.fi335+.336+.IP "" 0337+.338 .SS "Error Handling"339 Express provides the \fIapp\.error()\fR method which receives exceptions thrown within a route, or passed to \fInext(err)\fR\. Below is an example which serves different pages based on our ad\-hoc \fINotFound\fR exception:340 .341 .IP "" 422 unmodified lines364 .365 .P366 We can call \fIapp\.error()\fR several times as shown below\. Here we check for an instanceof \fINotFound\fR and show the 404 page, or we pass on to the next error handler\.367 .368+.P369+Note that these handlers can be defined anywhere, as they will be placed below the route handlers on \fIlisten()\fR\. This allows for definition within \fIconfigure()\fR blocks so we can handle exceptions in different ways based on the environment\.370+.371 .IP "" 4372 .373 .nf374 34 unmodified lines409 .IP "" 4410 .411 .nf412 378-app\.use(connect\.errorHandler({ dumpExceptions: true }));413+app\.use(express\.errorHandler({ dumpExceptions: true }));414 .415 .fi416 .417 .IP "" 04 unmodified lines422 .IP "" 4423 .424 .nf425 391-app\.use(connect\.errorHandler({ showStack: true, dumpExceptions: true }));426+app\.use(express\.errorHandler({ showStack: true, dumpExceptions: true }));427 .428 .fi429 .430 .IP "" 01 unmodified line432 .P433 The \fIerrorHandler\fR middleware also responds with \fIjson\fR if \fIAccept: application/json\fR is present, which is useful for developing apps that rely heavily on client\-side JavaScript\.434 .435 .SS "View Rendering"401-View filenames take the form \fINAME\fR\.\fIENGINE\fR, where \fIENGINE\fR is the name of the module that will be required\. For example the view \fIlayout\.ejs\fR will tell the view system to \fIrequire(\'ejs\')\fR, the module being loaded must (currently) export the method \fIexports\.render(str, options)\fR to comply with Express, however with will likely be extensible in the future\.436+View filenames take the form \fINAME\fR\.\fIENGINE\fR, where \fIENGINE\fR is the name of the module that will be required\. For example the view \fIlayout\.ejs\fR will tell the view system to \fIrequire(\'ejs\')\fR, the module being loaded must export the method \fIexports\.render(str, options)\fR to comply with Express, however \fIapp\.register()\fR can be used to map engines to file extensions, so that for example \"foo\.html\" can be rendered by jade\.437 .438 .P439 Below is an example using Haml\.js \fIhttp://github\.com/visionmedia/haml\.js\fR to render \fIindex\.html\fR, and since we do not use \fIlayout: false\fR the rendered contents of \fIindex\.html\fR will be passed as the \fIbody\fR local variable in \fIlayout\.haml\fR\.440 .62 unmodified lines503 .fi504 .505 .IP "" 0506 .507+.P508+Express also provides the \fIview options\fR setting, which is applied each time a view is rendered, so for example if you rarely use layouts you may set:509+.510+.IP "" 4511+.512+.nf513+514+app\.set(\'view options\', {515+ layout: false516+});517+.518+.fi519+.520+.IP "" 0521+.522+.P523+Which can then be overridden within the \fBres\.render()\fR call if need be:524+.525+.IP "" 4526+.527+.nf528+529+res\.render(\'myview\.ejs\', { layout: true });530+.531+.fi532+.533+.IP "" 0534+.535+.P536+A good example of this is specifying custom \fIejs\fR opening and closing tags:537+.538+.IP "" 4539+.540+.nf541+542+app\.set(\'view options\', {543+ open: \'{{\',544+ close: \'}}\'545+});546+.547+.fi548+.549+.IP "" 0550+.551 .SS "View Partials"552 The Express view system has built\-in support for partials and collections, which are sort of \"mini\" views representing a document fragment\. For example rather than iterating in a view to display comments, we would use a partial with collection support:553 .554 .IP "" 4118 unmodified lines673 .674 .IP "" 0675 .676 .P598-To utilize urlencoded request bodies, \fIreq\.body\fR should be an object\. This can be done by using the \fIconnect\.bodyDecoder\fR middleware\.677+To utilize urlencoded request bodies, \fIreq\.body\fR should be an object\. This can be done by using the \fIexpress\.bodyDecoder\fR middleware\.678 .679 .SS "req\.flash(type[, msg])"680 Queue flash \fImsg\fR of the given \fItype\fR\.681 .472 unmodified lines1154 .fi1155 .1156 .IP "" 01157 .1158+.SS "app\.register(ext, exports)"1159+Register the given template engine \fIexports\fR as \fIext\fR\. For example we may wish to map \"\.html\" files to jade:1160+.1161+.IP "" 41162+.1163+.nf1164+1165+ app\.register(\'\.html\', require(\'jade\'));1166+.1167+.fi1168+.1169+.IP "" 01170+.1171+.P1172+This is also useful for libraries that may not match extensions correctly\. For example my haml\.js library is installed from npm as \"hamljs\" so instead of layout\.hamljs, we can register the engine as \"\.haml\":1173+.1174+.IP "" 41175+.1176+.nf1177+1178+ app\.register(\'\.haml\', require(\'haml\-js\'));1179+.1180+.fi1181+.1182+.IP "" 01183+.1184+.P1185+For engines that do not comply with the Express specification, we can also wrap their api this way\.1186+.1187+.IP "" 41188+.1189+.nf1190+1191+ app\.register(\'\.foo\', {1192+ render: function(str, options) {1193+ // perhaps their api is1194+ // foo\.toHTML(str, options);1195+ }1196+ });1197+.1198+.fi1199+.1200+.IP "" 01201+.1202 .SS "app\.listen([port[, host]])"1203 Bind the app server to the given \fIport\fR, which defaults to 3000\. When \fIhost\fR is omitted all connections will be accepted via \fIINADDR_ANY\fR\.1204 .1205 .IP "" 444 unmodified linesmodified:docs/guide.html+81 added-16 removed
211 unmodified lines212 <li><a href="#app-error-function-">app.error()</a></li>213 <li><a href="#app-helpers-obj-">app.helpers()</a></li>214 <li><a href="#app-dynamicHelpers-obj-">app.dynamicHelpers()</a></li>215 <li><a href="#app-mounted-fn-">app.mounted()</a></li>216+<li><a href="#app-register-ext-exports-">app.register()</a></li>217 <li><a href="#app-listen-port-host-">app.listen()</a></li>218 </ul>219 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 220 <p id="tagline">53 unmodified lines274 Note the use of <em>app.router</em>, which can (optionally) be used to mount the application routes,275 otherwise the first call to <em>app.{get,put,del,post}()</em> will mount the routes.</p>276 277 <pre><code>app.configure(function(){277- app.use(connect.methodOverride());278- app.use(connect.bodyDecoder());278+ app.use(express.methodOverride());279+ app.use(express.bodyDecoder());280 app.use(app.router);280- app.use(connect.staticProvider(__dirname + '/public'));281+ app.use(express.staticProvider(__dirname + '/public'));282 });283 284 app.configure('development', function(){284- app.use(connect.errorHandler({ dumpExceptions: true, showStack: true }));285+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));286 });287 288 app.configure('production', function(){288- app.use(connect.errorHandler());289+ app.use(express.errorHandler());290 });291 </code></pre>292 293 <p>For internal and arbitrary settings Express provides the <em>set(key[, val])</em>, <em>enable(key)</em>, <em>disable(key)</em> methods:</p>25 unmodified lines319 <li><em>env</em> Application environment set internally, use <em>app.set('env')</em> on <em>Server#listen()</em></li>320 <li><em>home</em> Application base path used for <em>res.redirect()</em> and transparently handling mounted apps.</li>321 <li><em>views</em> Root views directory defaulting to <strong>CWD/views</strong></li>322 <li><em>view engine</em> Default view engine name for views rendered without extensions</li>323+<li><em>view options</em> An object specifying global view options</li>324+<li><em>partials</em> Root view partials directory defaulting to <em>views</em>/partials.</li>325 </ul>326 327 328 <h3 id="Routing">Routing</h3>90 unmodified lines419 420 <p>The Express <em>Plugin</em> is no more! middleware via <a href="http://github.com/extjs/Connect">Connect</a> can be421 passed to <em>express.createServer()</em> as you would with a regular Connect server. For example:</p>422 420-<pre><code>var connect = require('connect'),421- express = require('express');423+<pre><code>var express = require('express');424 425 var app = express.createServer(424- connect.logger(),425- connect.bodyDecoder()426+ express.logger(),427+ express.bodyDecoder()428 );429 </code></pre>430 431 <p>Alternatively we can <em>use()</em> them which is useful when adding middleware within <em>configure()</em> blocks:</p>432 431-<pre><code>app.use(connect.logger({ format: ':method :uri' }));433+<pre><code>app.use(express.logger({ format: ':method :uri' }));434 </code></pre>435 436+<p>Typically with connect middleware you would <em>require('connect')</em> like so:</p>437+438+<pre><code>var connect = require('connect');439+app.use(connect.logger());440+</code></pre>441+442+<p>This is somewhat annoying, so express re-exports these middleware properties, however they are <em>identical</em>:</p>443+444+<pre><code>app.use(express.logger());445+</code></pre>446+447 <h3 id="Error-Handling">Error Handling</h3>448 449 <p>Express provides the <em>app.error()</em> method which receives exceptions thrown within a route,450 or passed to <em>next(err)</em>. Below is an example which serves different pages based on our19 unmodified lines470 <p>We can call <em>app.error()</em> several times as shown below.471 Here we check for an instanceof <em>NotFound</em> and show the472 404 page, or we pass on to the next error handler.</p>473 474+<p>Note that these handlers can be defined anywhere, as they475+will be placed below the route handlers on <em>listen()</em>. This476+allows for definition within <em>configure()</em> blocks so we can477+handle exceptions in different ways based on the environment.</p>478+479 <pre><code>app.error(function(err, req, res, next){480 if (err instanceof NotFound) {481 res.render('404.jade');482 } else {17 unmodified lines500 <p>Our apps could also utilize the Connect <em>errorHandler</em> middleware501 to report on exceptions. For example if we wish to output exceptions502 in "development" mode to <em>stderr</em> we can use:</p>503 486-<pre><code>app.use(connect.errorHandler({ dumpExceptions: true }));504+<pre><code>app.use(express.errorHandler({ dumpExceptions: true }));505 </code></pre>506 507 <p>Also during development we may want fancy html pages to show exceptions508 that are passed or thrown, so we can set <em>showStack</em> to true:</p>509 492-<pre><code>app.use(connect.errorHandler({ showStack: true, dumpExceptions: true }));510+<pre><code>app.use(express.errorHandler({ showStack: true, dumpExceptions: true }));511 </code></pre>512 513 <p>The <em>errorHandler</em> middleware also responds with <em>json</em> if <em>Accept: application/json</em>514 is present, which is useful for developing apps that rely heavily on client-side JavaScript.</p>1 unmodified line516 <h3 id="View-Rendering">View Rendering</h3>517 518 <p>View filenames take the form <em>Express</em>.<em>ENGINE</em>, where <em>ENGINE</em> is the name519 of the module that will be required. For example the view <em>layout.ejs</em> will502-tell the view system to <em>require('ejs')</em>, the module being loaded must (currently)503-export the method <em>exports.render(str, options)</em> to comply with Express, however504-with will likely be extensible in the future.</p>520+tell the view system to <em>require('ejs')</em>, the module being loaded must export the method <em>exports.render(str, options)</em> to comply with Express, however521+<em>app.register()</em> can be used to map engines to file extensions, so that for example "foo.html" can be rendered by jade.</p>522 523 <p>Below is an example using <a href="http://github.com/visionmedia/haml.js">Haml.js</a> to render <em>index.html</em>,524 and since we do not use <em>layout: false</em> the rendered contents of <em>index.html</em> will be passed as525 the <em>body</em> local variable in <em>layout.haml</em>.</p>26 unmodified lines552 553 <pre><code>res.render('another-page.ejs');554 </code></pre>555 556+<p>Express also provides the <em>view options</em> setting, which is applied each time a view is rendered, so for example if you rarely use layouts you may set:</p>557+558+<pre><code>app.set('view options', {559+ layout: false560+});561+</code></pre>562+563+<p>Which can then be overridden within the <code>res.render()</code> call if need be:</p>564+565+<pre><code>res.render('myview.ejs', { layout: true });566+</code></pre>567+568+<p>A good example of this is specifying custom <em>ejs</em> opening and closing tags:</p>569+570+<pre><code>app.set('view options', {571+ open: '{{',572+ close: '}}'573+});574+</code></pre>575+576 <h3 id="View-Partials">View Partials</h3>577 578 <p>The Express view system has built-in support for partials and collections, which are579 sort of "mini" views representing a document fragment. For example rather than iterating81 unmodified lines661 662 663 <p>To utilize urlencoded request bodies, <em>req.body</em>664 should be an object. This can be done by using628-the <em>connect.bodyDecoder</em> middleware.</p>665+the <em>express.bodyDecoder</em> middleware.</p>666 667 <h3 id="req-flash-type-msg-">req.flash(type[, msg])</h3>668 669 <p>Queue flash <em>msg</em> of the given <em>type</em>.</p>304 unmodified lines974 975 app.use(blog);976 </code></pre>977 978+<h3 id="app-register-ext-exports-">app.register(ext, exports)</h3>979+980+<p>Register the given template engine <em>exports</em>981+as <em>ext</em>. For example we may wish to map ".html"982+files to jade:</p>983+984+<pre><code> app.register('.html', require('jade'));985+</code></pre>986+987+<p>This is also useful for libraries that may not988+match extensions correctly. For example my haml.js989+library is installed from npm as "hamljs" so instead990+of layout.hamljs, we can register the engine as ".haml":</p>991+992+<pre><code> app.register('.haml', require('haml-js'));993+</code></pre>994+995+<p>For engines that do not comply with the Express996+specification, we can also wrap their api this way.</p>997+998+<pre><code> app.register('.foo', {999+ render: function(str, options) {1000+ // perhaps their api is1001+ // foo.toHTML(str, options);1002+ }1003+ });1004+</code></pre>1005+1006 <h3 id="app-listen-port-host-">app.listen([port[, host]])</h3>1007 1008 <p>Bind the app server to the given <em>port</em>, which defaults to 3000. When <em>host</em> is omitted all1009 connections will be accepted via <em>INADDR_ANY</em>.</p>28 unmodified linesmodified:docs/guide.md+27 added-3 removed
261 unmodified lines262 ### View Rendering263 264 View filenames take the form _NAME_._ENGINE_, where _ENGINE_ is the name265 of the module that will be required. For example the view _layout.ejs_ will266-tell the view system to _require('ejs')_, the module being loaded must (currently)267-export the method _exports.render(str, options)_ to comply with Express, however 268-with will likely be extensible in the future.266+tell the view system to _require('ejs')_, the module being loaded must export the method _exports.render(str, options)_ to comply with Express, however 267+_app.register()_ can be used to map engines to file extensions, so that for example "foo.html" can be rendered by jade.268 269 Below is an example using [Haml.js](http://github.com/visionmedia/haml.js) to render _index.html_,270 and since we do not use _layout: false_ the rendered contents of _index.html_ will be passed as 271 the _body_ local variable in _layout.haml_.390 unmodified lines662 });663 664 app.use(blog);665 666+### app.register(ext, exports)667+668+Register the given template engine _exports_669+as _ext_. For example we may wish to map ".html"670+files to jade:671+672+ app.register('.html', require('jade'));673+674+This is also useful for libraries that may not675+match extensions correctly. For example my haml.js676+library is installed from npm as "hamljs" so instead677+of layout.hamljs, we can register the engine as ".haml":678+679+ app.register('.haml', require('haml-js'));680+681+For engines that do not comply with the Express682+specification, we can also wrap their api this way.683+684+ app.register('.foo', {685+ render: function(str, options) {686+ // perhaps their api is687+ // foo.toHTML(str, options);688+ }689+ });690+691 ### app.listen([port[, host]])692 693 Bind the app server to the given _port_, which defaults to 3000. When _host_ is omitted all694 connections will be accepted via _INADDR_ANY_.19 unmodified linesmodified:docs/index.1+7 added-1 removed
1 .\" generated with Ronn/v0.6.62 .\" http://github.com/rtomayko/ronn/3 .4-.TH "INDEX" "" "July 2010" "" ""4+.TH "INDEX" "" "August 2010" "" ""5 .6 .IP "" 47 .8 .nf21 unmodified lines30 .IP "\(bu" 431 Dynamic view helpers32 .33 .IP "\(bu" 434+Application level view options35+.36+.IP "\(bu" 437 Content negotiation38 .39 .IP "\(bu" 440 Focus on high performance82 unmodified lines123 .124 .IP "\(bu" 4125 Storify \fIhttp://storify\.com\fR \- The future of publishing126 .127+.IP "\(bu" 4128+Ogre \fIhttp://ogre\.adc4gis\.com/\fR \- Translates spatial files into GeoJSON129+.130 .IP "" 0131 modified:docs/index.html+2 added
204 unmodified lines205 <ul>206 <li>Robust routing</li>207 <li>Redirection helpers</li>208 <li>Dynamic view helpers</li>209+<li>Application level view options</li>210 <li>Content negotiation</li>211 <li>Focus on high performance</li>212 <li>View rendering and partials support</li>213 <li>Environment based configuration</li>38 unmodified lines252 <li><a href="http://codeshelver.com/">Code Shelver</a> - GitHub watch list app</li>253 <li><a href="http://clickdummy.net/">Clickdummy</a> - Fast prototyping for designers</li>254 <li><a href="http://e-resistible.co.uk">E-Resistible</a> - Online takeaway ordering app</li>255 <li><a href="http://storify.com">Storify</a> - The future of publishing</li>256+<li><a href="http://ogre.adc4gis.com/">Ogre</a> - Translates spatial files into GeoJSON</li>257 </ul>258 259 260 </div>4 unmodified linesmodified:docs/migrate.1+7 added-10 removed
1 .\" generated with Ronn/v0.6.62 .\" http://github.com/rtomayko/ronn/3 .4-.TH "MIGRATE" "" "July 2010" "" ""4+.TH "MIGRATE" "" "August 2010" "" ""5 .6 .SS "Built On Connect"7 Express 1\.x is written to run on\-top of the Connect \fIhttp://extjs\.github\.com/Connect\fR middlware framework, thus the \fIPlugin\fR has been replaced by Connect\'s middleware\. By abstracting our middleware to Connect we allow additional community frameworks to develop robust, high\-level frameworks using the same technologies as Express\.8 .64 unmodified lines73 .IP "" 474 .75 .nf76 77-var connect = require(\'connect\');78-77 var app = express\.createServer(80- connect\.logger(),81- connect\.methodOverride(),82- connect\.cookieDecoder()78+ express\.logger(),79+ express\.methodOverride(),80+ express\.cookieDecoder()81 );82 .83 .fi84 .5 unmodified lines90 .IP "" 491 .92 .nf93 96-var connect = require(\'connect\');94 var app = express\.createServer();95 99-app\.use(connect\.logger());100-app\.use(connect\.methodOverride());101-app\.use(connect\.cookieDecoder());96+app\.use(express\.logger());97+app\.use(express\.methodOverride());98+app\.use(express\.cookieDecoder());99 .100 .fi101 .102 .IP "" 0242 unmodified linesmodified:docs/migrate.html+8 added-11 removed
244 unmodified lines245 </code></pre>246 247 <p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>248 249-<pre><code>var connect = require('connect');250-251-var app = express.createServer(252- connect.logger(),253- connect.methodOverride(),254- connect.cookieDecoder()249+<pre><code>var app = express.createServer(250+ express.logger(),251+ express.methodOverride(),252+ express.cookieDecoder()253 );254 </code></pre>255 256 <p>or:</p>257 260-<pre><code>var connect = require('connect');261-var app = express.createServer();258+<pre><code>var app = express.createServer();259 263-app.use(connect.logger());264-app.use(connect.methodOverride());265-app.use(connect.cookieDecoder());260+app.use(express.logger());261+app.use(express.methodOverride());262+app.use(express.cookieDecoder());263 </code></pre>264 265 <p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>266 142 unmodified lines