Skip to content
Myr

Setting up TOC

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 0cdc836 · Browse files · 9 files+327 added−261 removed
This commit

State

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

Diff stats

9 files+327 added−261 removed

  • other:+327 added−261 removed

9 files+327 added−261 removed

modified:docs/layout/head.html+11 added
modified:docs/api.html+213 added-213 removed
335 unmodified lines
336<td class="code">337<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'isXMLHttpRequest'</span>, <span class="variable">isxhr</span>);338<span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'xhr'</span>, <span class="variable">isxhr</span>);</code></pre>339</td>340</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">341<td class="docs">342<p>Module dependencies.343 </p>344</td>345<td class="code">346<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),347 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),348 <span class="variable">view</span> = <span class="variable">require</span>(<span class="string">'./view'</span>),349 <span class="variable">connect</span> = <span class="variable">require</span>(<span class="string">'connect'</span>),350 <span class="variable">queryString</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>),351 <span class="variable">router</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/router'</span>);</code></pre>352</td>353</tr>354<tr class="code">355<td class="docs">356<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>357358<h2></h2>359360<ul><li><p><strong>param</strong>: <em>Array</em> middleware</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>361</td>362<td class="code">363<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>){364 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;365 <span class="this">this</span>.<span class="variable">config</span> = {};366 <span class="this">this</span>.<span class="variable">settings</span> = {};367 <span class="this">this</span>.<span class="variable">redirects</span> = {};368 <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> || []);369370 <span class="comment">// Expose objects to each other</span>371 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</span>, <span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){372 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};373 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};374 <span class="variable">res</span>.<span class="variable">headers</span> = {};375 <span class="variable">req</span>.<span class="variable">app</span> = <span class="variable">res</span>.<span class="variable">app</span> = <span class="variable">self</span>;376 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;377 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;378 <span class="comment">// Assign req.params.get</span>379 <span class="keyword">if</span> (<span class="variable">req</span>.<span class="variable">url</span>.<span class="variable">indexOf</span>(<span class="string">'?'</span>) &<span class="variable">gt</span>; <span class="number integer">0</span>) {380 <span class="comment">// TODO: consider simple substr to increase performance</span>381 <span class="keyword">var</span> <span class="variable">query</span> = <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">query</span>;382 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = <span class="variable">queryString</span>.<span class="variable">parse</span>(<span class="variable">query</span>);383 }384 <span class="variable">next</span>();385 });386387 <span class="comment">// Use router, expose as app.get(), etc</span>388 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</span>, <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){389 <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>;390 }));391};</code></pre>392</td>393</tr>394<tr class="code">395<td class="docs">396<p>Inherit from <code>connect.Server</code>.397 </p>398</td>399<td class="code">400<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>401</td>402</tr>403<tr class="code">404<td class="docs">405<p>Listen on the given <code>port</code> after running configuration blocks.</p>406407<h2></h2>408409<ul><li><p><strong>param</strong>: <em>Number</em> port</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>410</td>411<td class="code">412<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>){413 <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>);414 <span class="this">this</span>.<span class="variable">runConfig</span>(<span class="string">'any'</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>));415416 <span class="comment">// Setup view reloading</span>417 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {418 <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>));419 }420421 <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>);422};</code></pre>423</td>424</tr>425<tr class="code">426<td class="docs">427<p>Run config callbacks for the given environment(s);</p>428429<h2></h2>430431<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>432</td>433<td class="code">434<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">runConfig</span> = <span class="keyword">function</span>(){435 <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>) {436 <span class="keyword">var</span> <span class="variable">env</span> = <span class="variable">arguments</span>[<span class="variable">i</span>];437 <span class="keyword">if</span> (<span class="variable">env</span> <span class="keyword">in</span> <span class="this">this</span>.<span class="variable">config</span>) {438 <span class="keyword">var</span> <span class="variable">config</span> = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>];439 <span class="variable">config</span>.<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">fn</span>){440 <span class="variable">fn</span>.<span class="variable">call</span>(<span class="this">this</span>);441 }, <span class="this">this</span>);442 }443 }444 <span class="keyword">return</span> <span class="this">this</span>;445};</code></pre>446</td>447</tr>448<tr class="code">449<td class="docs">450<p>Assign a custom exception handler callback <code>fn</code>.</p>451452<h2></h2>453454<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>455</td>456<td class="code">457<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>){458 <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>){459 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);460 });461 <span class="keyword">return</span> <span class="this">this</span>;462};</code></pre>463</td>464</tr>465<tr class="code">466<td class="docs">467<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>468469<h2></h2>470471<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>472</td>473<td class="code">474<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>){475 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {476 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];477 } <span class="keyword">else</span> {478 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;479 <span class="keyword">return</span> <span class="this">this</span>;480 }481};</code></pre>482</td>483</tr>484<tr class="code">485<td class="docs">486<p>Enable <code>setting</code>.</p>487488<h2></h2>489490<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>491</td>492<td class="code">493<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>){494 <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>);495};</code></pre>496</td>497</tr>498<tr class="code">499<td class="docs">500<p>Disable <code>setting</code>.</p>501502<h2></h2>503504<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>505</td>506<td class="code">507<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>){508 <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>);509};</code></pre>510</td>511</tr>512<tr class="code">513<td class="docs">514<p>Redirect <code>key</code> to <code>url</code>.</p>515516<h2></h2>517518<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>519</td>520<td class="code">521<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>){522 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;523 <span class="keyword">return</span> <span class="this">this</span>;524};</code></pre>525</td>526</tr>527<tr class="code">528<td class="docs">529<p>Disable <code>setting</code>.</p>530531<h2></h2>532533<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>534</td>535<td class="code">536<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>){537 <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>;538 (<span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] || []).<span class="variable">push</span>(<span class="variable">fn</span>);539 <span class="keyword">return</span> <span class="this">this</span>;540};541542<span class="comment">// Generate routing methods</span>543544(<span class="keyword">function</span>(<span class="variable">method</span>){545 <span class="class">Server</span>.<span class="variable">prototype</span>[<span class="variable">method</span>] = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">fn</span>){546 <span class="this">this</span>.<span class="variable">routes</span>[<span class="variable">method</span>](<span class="variable">path</span>, <span class="variable">fn</span>);547 <span class="keyword">return</span> <span class="this">this</span>;548 };549 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;550})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);551</code></pre>552</td>553</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">554<td class="docs">555<p>Module dependencies.556 </p>
235 unmodified lines
792 <span class="this">this</span>.<span class="variable">end</span>();793};794</code></pre>795</td>583</tr><tr class="filename"><td><h2 id="lib/express/server.js"><a href="#">server</a></h2></td><td>lib/express/server.js</td></tr><tr class="code">584<td class="docs">585<p>Module dependencies.586 </p>587</td>588<td class="code">589<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),590 <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>),591 <span class="variable">view</span> = <span class="variable">require</span>(<span class="string">'./view'</span>),592 <span class="variable">connect</span> = <span class="variable">require</span>(<span class="string">'connect'</span>),593 <span class="variable">queryString</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>),594 <span class="variable">router</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/router'</span>);</code></pre>595</td>596</tr>597<tr class="code">598<td class="docs">599<p>Initialize a new <code>Server</code> with optional <code>middleware</code>.</p>600601<h2></h2>602603<ul><li><p><strong>param</strong>: <em>Array</em> middleware</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>604</td>605<td class="code">606<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>){607 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;608 <span class="this">this</span>.<span class="variable">config</span> = {};609 <span class="this">this</span>.<span class="variable">settings</span> = {};610 <span class="this">this</span>.<span class="variable">redirects</span> = {};611 <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> || []);612613 <span class="comment">// Expose objects to each other</span>614 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</span>, <span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){615 <span class="variable">req</span>.<span class="variable">params</span> = <span class="variable">req</span>.<span class="variable">params</span> || {};616 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = {};617 <span class="variable">res</span>.<span class="variable">headers</span> = {};618 <span class="variable">req</span>.<span class="variable">app</span> = <span class="variable">res</span>.<span class="variable">app</span> = <span class="variable">self</span>;619 <span class="variable">req</span>.<span class="variable">res</span> = <span class="variable">res</span>;620 <span class="variable">res</span>.<span class="variable">req</span> = <span class="variable">req</span>;621 <span class="comment">// Assign req.params.get</span>622 <span class="keyword">if</span> (<span class="variable">req</span>.<span class="variable">url</span>.<span class="variable">indexOf</span>(<span class="string">'?'</span>) &<span class="variable">gt</span>; <span class="number integer">0</span>) {623 <span class="comment">// TODO: consider simple substr to increase performance</span>624 <span class="keyword">var</span> <span class="variable">query</span> = <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">query</span>;625 <span class="variable">req</span>.<span class="variable">params</span>.<span class="variable">get</span> = <span class="variable">queryString</span>.<span class="variable">parse</span>(<span class="variable">query</span>);626 }627 <span class="variable">next</span>();628 });629630 <span class="comment">// Use router, expose as app.get(), etc</span>631 <span class="this">this</span>.<span class="variable">use</span>(<span class="string">'/'</span>, <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){632 <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>;633 }));634};</code></pre>635</td>636</tr>637<tr class="code">638<td class="docs">639<p>Inherit from <code>connect.Server</code>.640 </p>641</td>642<td class="code">643<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>644</td>645</tr>646<tr class="code">647<td class="docs">648<p>Listen on the given <code>port</code> after running configuration blocks.</p>649650<h2></h2>651652<ul><li><p><strong>param</strong>: <em>Number</em> port</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>653</td>654<td class="code">655<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>){656 <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>);657 <span class="this">this</span>.<span class="variable">runConfig</span>(<span class="string">'any'</span>, <span class="this">this</span>.<span class="variable">set</span>(<span class="string">'env'</span>));658659 <span class="comment">// Setup view reloading</span>660 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">set</span>(<span class="string">'reload views'</span>)) {661 <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>));662 }663664 <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>);665};</code></pre>666</td>667</tr>668<tr class="code">669<td class="docs">670<p>Run config callbacks for the given environment(s);</p>671672<h2></h2>673674<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>675</td>676<td class="code">677<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">runConfig</span> = <span class="keyword">function</span>(){678 <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>) {679 <span class="keyword">var</span> <span class="variable">env</span> = <span class="variable">arguments</span>[<span class="variable">i</span>];680 <span class="keyword">if</span> (<span class="variable">env</span> <span class="keyword">in</span> <span class="this">this</span>.<span class="variable">config</span>) {681 <span class="keyword">var</span> <span class="variable">config</span> = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>];682 <span class="variable">config</span>.<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">fn</span>){683 <span class="variable">fn</span>.<span class="variable">call</span>(<span class="this">this</span>);684 }, <span class="this">this</span>);685 }686 }687 <span class="keyword">return</span> <span class="this">this</span>;688};</code></pre>689</td>690</tr>691<tr class="code">692<td class="docs">693<p>Assign a custom exception handler callback <code>fn</code>.</p>694695<h2></h2>696697<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>698</td>699<td class="code">700<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>){701 <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>){702 <span class="variable">fn</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);703 });704 <span class="keyword">return</span> <span class="this">this</span>;705};</code></pre>706</td>707</tr>708<tr class="code">709<td class="docs">710<p>Assign <code>setting</code> to <code>val</code>, or return <code>setting</code>'s value.</p>711712<h2></h2>713714<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>715</td>716<td class="code">717<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>){718 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {719 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>];720 } <span class="keyword">else</span> {721 <span class="this">this</span>.<span class="variable">settings</span>[<span class="variable">setting</span>] = <span class="variable">val</span>;722 <span class="keyword">return</span> <span class="this">this</span>;723 }724};</code></pre>725</td>726</tr>727<tr class="code">728<td class="docs">729<p>Enable <code>setting</code>.</p>730731<h2></h2>732733<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>734</td>735<td class="code">736<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>){737 <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>);738};</code></pre>739</td>740</tr>741<tr class="code">742<td class="docs">743<p>Disable <code>setting</code>.</p>744745<h2></h2>746747<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>748</td>749<td class="code">750<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>){751 <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>);752};</code></pre>753</td>754</tr>755<tr class="code">756<td class="docs">757<p>Redirect <code>key</code> to <code>url</code>.</p>758759<h2></h2>760761<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>762</td>763<td class="code">764<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>){765 <span class="this">this</span>.<span class="variable">redirects</span>[<span class="variable">key</span>] = <span class="variable">url</span>;766 <span class="keyword">return</span> <span class="this">this</span>;767};</code></pre>768</td>769</tr>770<tr class="code">771<td class="docs">772<p>Disable <code>setting</code>.</p>773774<h2></h2>775776<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>777</td>778<td class="code">779<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>){780 <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>;781 (<span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] = <span class="this">this</span>.<span class="variable">config</span>[<span class="variable">env</span>] || []).<span class="variable">push</span>(<span class="variable">fn</span>);782 <span class="keyword">return</span> <span class="this">this</span>;783};784785<span class="comment">// Generate routing methods</span>786787(<span class="keyword">function</span>(<span class="variable">method</span>){788 <span class="class">Server</span>.<span class="variable">prototype</span>[<span class="variable">method</span>] = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">fn</span>){789 <span class="this">this</span>.<span class="variable">routes</span>[<span class="variable">method</span>](<span class="variable">path</span>, <span class="variable">fn</span>);790 <span class="keyword">return</span> <span class="this">this</span>;791 };792 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;793})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);794</code></pre>795</td>796</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">797<td class="docs">798<p>Parse mini markdown implementation.799The following conversions are supported,
256 unmodified lines
modified:docs/contrib.html+11 added
110 unmodified lines
111 margin: 0 auto;112 padding-top: 110px;113 width: 550px; }114115 #toc {116 position: fixed;117 top: 70px;118 left: 0;119 margin: 0 0 0 15px;120 padding: 0;121 }122 #toc li {123 list-style: none;124 }125126 #menu {127 margin-left: 65px;128 padding: 0;129 padding-bottom: 30px; }
84 unmodified lines
modified:docs/executable.html+11 added
110 unmodified lines
111 margin: 0 auto;112 padding-top: 110px;113 width: 550px; }114115 #toc {116 position: fixed;117 top: 70px;118 left: 0;119 margin: 0 0 0 15px;120 padding: 0;121 }122 #toc li {123 list-style: none;124 }125126 #menu {127 margin-left: 65px;128 padding: 0;129 padding-bottom: 30px; }
66 unmodified lines
modified:docs/guide.1+12 added-12 removed
248 unmodified lines
249.fi250.251.IP "" 0252.253.SS "ServerRequest#header(key[, defaultValue])"253.SS "Request#header(key[, defaultValue])"254Get the case\-insensitive request header \fIkey\fR, with optional \fIdefaultValue\fR:255.256.IP "" 4257.
6 unmodified lines
264.fi265.266.IP "" 0267.268.SS "ServerRequest#accepts(type)"268.SS "Request#accepts(type)"269Check if the \fIAccept\fR header is present, and includes the given \fItype\fR\.270.271.P272When the \fIAccept\fR header is not present \fItrue\fR is returned\. Otherwise the given \fItype\fR is matched by an exact match, and then subtypes\. You may pass the subtype such as \"html\" which is then converted internally to \"text/html\" using the mime lookup table\.
20 unmodified lines
293.fi294.295.IP "" 0296.297.SS "ServerRequest#param(name)"297.SS "Request#param(name)"298Return the value of param \fIname\fR when present\.299.300.IP "\(bu" 4301Checks route placeholders, ex: /user/:id
8 unmodified lines
310.311.P312To utilize urlencoded request bodies, \fIreq\.body\fR should be an object\. This can be done by using the \fIconnect\.bodyDecoder\fR middleware\.313.314.SS "ServerRequest#flash(type[, msg])"314.SS "Request#flash(type[, msg])"315Queue flash \fImsg\fR of the given \fItype\fR\.316.317.IP "" 4318.
16 unmodified lines
335.fi336.337.IP "" 0338.339.SS "ServerRequest#isXMLHttpRequest"339.SS "Request#isXMLHttpRequest"340Also aliased as \fIreq\.xhr\fR, this getter checks the \fIX\-Requested\-With\fR header to see if it was issued by an \fIXMLHttpRequest\fR:341.342.IP "" 4343.
5 unmodified lines
349.fi350.351.IP "" 0352.353.SS "ServerResponse#header(key[, val])"353.SS "Response#header(key[, val])"354Get or set the response header \fIkey\fR\.355.356.IP "" 4357.
11 unmodified lines
369.fi370.371.IP "" 0372.373.SS "ServerResponse#contentType(type)"373.SS "Response#contentType(type)"374Sets the \fIContent\-Type\fR response header to the given \fItype\fR\.375.376.IP "" 4377.
6 unmodified lines
384.fi385.386.IP "" 0387.388.SS "ServerResponse#attachment([filename])"388.SS "Response#attachment([filename])"389Sets the \fIContent\-Disposition\fR response header to \"attachment\", with optional \fIfilename\fR\.390.391.IP "" 4392.
4 unmodified lines
397.fi398.399.IP "" 0400.401.SS "ServerResponse#sendfile(path)"401.SS "Response#sendfile(path)"402Used by \fBres\.download()\fR to transfer an arbitrary file\.403.404.IP "" 4405.
7 unmodified lines
413.414.P415\fBNOTE\fR: this is \fInot\fR a replacement for Connect\'s \fIstaticProvider\fR middleware, nor does it perform any security checks, use with caution when using in a dynamic manor\.416.417.SS "ServerResponse#download(file[, filename])"417.SS "Response#download(file[, filename])"418Transfer the given \fIfile\fR as an attachment with optional alternative \fIfilename\fR\.419.420.IP "" 4421.
19 unmodified lines
441.fi442.443.IP "" 0444.445.SS "ServerRequest#send(body|status[, headers|status[, status]])"445.SS "Response#send(body|status[, headers|status[, status]])"446The \fBres\.send()\fR method is a high level response utility allowing you to pass objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status code based responses\. The following are all valid uses:447.448.IP "" 4449.
12 unmodified lines
462.463.P464By default the \fIContent\-Type\fR response header is set, however if explicitly assigned through \fBres\.send()\fR or previously with \fBres\.header()\fR or \fBres\.contentType()\fR it will not be set again\.465.466.SS "ServerResponse#redirect(url[, status])"466.SS "Response#redirect(url[, status])"467Redirect to the given \fIurl\fR with a default response \fIstatus\fR of 302\.468.469.IP "" 4470.
64 unmodified lines
modified:docs/guide.html+35 added-24 removed
110 unmodified lines
111 margin: 0 auto;112 padding-top: 110px;113 width: 550px; }114115 #toc {116 position: fixed;117 top: 70px;118 left: 0;119 margin: 0 0 0 15px;120 padding: 0;121 }122 #toc li {123 list-style: none;124 }125126 #menu {127 margin-left: 65px;128 padding: 0;129 padding-bottom: 30px; }
35 unmodified lines
165<li><a href="#Settings">Settings</a></li>166<li><a href="#Routing">Routing</a></li>167<li><a href="#Passing-Route-Control">Passing Route Control</a></li>168<li><a href="#Middleware">Middleware</a></li>158<li><a href="#ServerRequest-header-key-defaultValue-">ServerRequest#header(key[, defaultValue])</a></li>159<li><a href="#ServerRequest-accepts-type-">ServerRequest#accepts(type)</a></li>160<li><a href="#ServerRequest-param-name-">ServerRequest#param(name)</a></li>161<li><a href="#ServerRequest-flash-type-msg-">ServerRequest#flash(type[, msg])</a></li>162<li><a href="#ServerRequest-isXMLHttpRequest">ServerRequest#isXMLHttpRequest</a></li>163<li><a href="#ServerResponse-header-key-val-">ServerResponse#header(key[, val])</a></li>164<li><a href="#ServerResponse-contentType-type-">ServerResponse#contentType(type)</a></li>165<li><a href="#ServerResponse-attachment-filename-">ServerResponse#attachment([filename])</a></li>166<li><a href="#ServerResponse-sendfile-path-">ServerResponse#sendfile(path)</a></li>167<li><a href="#ServerResponse-download-file-filename-">ServerResponse#download(file[, filename])</a></li>168<li><a href="#ServerRequest-send-body-status-headers-status-status-">ServerRequest#send(body|status[, headers|status[, status]])</a></li>169<li><a href="#ServerResponse-redirect-url-status-">ServerResponse#redirect(url[, status])</a></li>169<li><a href="#Request-header-key-defaultValue-">Request#header(key[, defaultValue])</a></li>170<li><a href="#Request-accepts-type-">Request#accepts(type)</a></li>171<li><a href="#Request-param-name-">Request#param(name)</a></li>172<li><a href="#Request-flash-type-msg-">Request#flash(type[, msg])</a></li>173<li><a href="#Request-isXMLHttpRequest">Request#isXMLHttpRequest</a></li>174<li><a href="#Response-header-key-val-">Response#header(key[, val])</a></li>175<li><a href="#Response-contentType-type-">Response#contentType(type)</a></li>176<li><a href="#Response-attachment-filename-">Response#attachment([filename])</a></li>177<li><a href="#Response-sendfile-path-">Response#sendfile(path)</a></li>178<li><a href="#Response-download-file-filename-">Response#download(file[, filename])</a></li>179<li><a href="#Response-send-body-status-headers-status-status-">Response#send(body|status[, headers|status[, status]])</a></li>180<li><a href="#Response-redirect-url-status-">Response#redirect(url[, status])</a></li>181<li><a href="#Server-redirect-name-val-">Server#redirect(name, val)</a></li>182</ul>183 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 184 <p id="tagline">
177 unmodified lines
362 connect.bodyDecoder()363);364</code></pre>365355<h3 id="ServerRequest-header-key-defaultValue-">ServerRequest#header(key[, defaultValue])</h3>366<h3 id="Request-header-key-defaultValue-">Request#header(key[, defaultValue])</h3>367368<p>Get the case-insensitive request header <em>key</em>, with optional <em>defaultValue</em>:</p>369370<pre><code>req.header('Host');371req.header('host');372req.header('Accept', '*/*');373</code></pre>374364<h3 id="ServerRequest-accepts-type-">ServerRequest#accepts(type)</h3>375<h3 id="Request-accepts-type-">Request#accepts(type)</h3>376377<p>Check if the <em>Accept</em> header is present, and includes the given <em>type</em>.</p>378379<p>When the <em>Accept</em> header is not present <em>true</em> is returned. Otherwise
16 unmodified lines
396req.accepts('png');397// =&gt; false398</code></pre>399389<h3 id="ServerRequest-param-name-">ServerRequest#param(name)</h3>400<h3 id="Request-param-name-">Request#param(name)</h3>401402<p>Return the value of param <em>name</em> when present.</p>403404<ul>
6 unmodified lines
411<p>To utilize urlencoded request bodies, <em>req.body</em>412should be an object. This can be done by using413the <em>connect.bodyDecoder</em> middleware.</p>414404<h3 id="ServerRequest-flash-type-msg-">ServerRequest#flash(type[, msg])</h3>415<h3 id="Request-flash-type-msg-">Request#flash(type[, msg])</h3>416417<p>Queue flash <em>msg</em> of the given <em>type</em>.</p>418419<pre><code>req.flash('info', 'email sent');
10 unmodified lines
430req.flash();431// =&gt; { error: ['email delivery failed'], info: [] }432</code></pre>433423<h3 id="ServerRequest-isXMLHttpRequest">ServerRequest#isXMLHttpRequest</h3>434<h3 id="Request-isXMLHttpRequest">Request#isXMLHttpRequest</h3>435436<p>Also aliased as <em>req.xhr</em>, this getter checks the <em>X-Requested-With</em> header437to see if it was issued by an <em>XMLHttpRequest</em>:</p>438439<pre><code>req.xhr440req.isXMLHttpRequest441</code></pre>442432<h3 id="ServerResponse-header-key-val-">ServerResponse#header(key[, val])</h3>443<h3 id="Response-header-key-val-">Response#header(key[, val])</h3>444445<p>Get or set the response header <em>key</em>.</p>446447<pre><code>res.header('Content-Length');
5 unmodified lines
453res.header('Content-Length');454// =&gt; 123455</code></pre>456446<h3 id="ServerResponse-contentType-type-">ServerResponse#contentType(type)</h3>457<h3 id="Response-contentType-type-">Response#contentType(type)</h3>458459<p>Sets the <em>Content-Type</em> response header to the given <em>type</em>.</p>460461<pre><code> var filename = 'path/to/image.png';462 res.contentType(filename);463 // res.headers['Content-Type'] is now "image/png"464</code></pre>465455<h3 id="ServerResponse-attachment-filename-">ServerResponse#attachment([filename])</h3>466<h3 id="Response-attachment-filename-">Response#attachment([filename])</h3>467468<p>Sets the <em>Content-Disposition</em> response header to "attachment", with optional <em>filename</em>.</p>469470<pre><code> res.attachment('path/to/my/image.png');471</code></pre>472462<h3 id="ServerResponse-sendfile-path-">ServerResponse#sendfile(path)</h3>473<h3 id="Response-sendfile-path-">Response#sendfile(path)</h3>474475<p>Used by <code>res.download()</code> to transfer an arbitrary file.</p>476477<pre><code>res.sendfile('path/to/my.file');
1 unmodified line
479480<p><strong>NOTE</strong>: this is <em>not</em> a replacement for Connect's <em>staticProvider</em> middleware,481nor does it perform any security checks, use with caution when using in a dynamic manor.</p>482472<h3 id="ServerResponse-download-file-filename-">ServerResponse#download(file[, filename])</h3>483<h3 id="Response-download-file-filename-">Response#download(file[, filename])</h3>484485<p>Transfer the given <em>file</em> as an attachment with optional alternative <em>filename</em>.</p>486487<pre><code>res.download('path/to/image.png');
5 unmodified lines
493<pre><code>res.attachment(file);494res.sendfile(file);495</code></pre>496486<h3 id="ServerRequest-send-body-status-headers-status-status-">ServerRequest#send(body|status[, headers|status[, status]])</h3>497<h3 id="Response-send-body-status-headers-status-status-">Response#send(body|status[, headers|status[, status]])</h3>498499<p>The <code>res.send()</code> method is a high level response utility allowing you to pass500objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status501code based responses. The following are all valid uses:</p>
9 unmodified lines
511<p>By default the <em>Content-Type</em> response header is set, however if explicitly512assigned through <code>res.send()</code> or previously with <code>res.header()</code> or <code>res.contentType()</code>513it will not be set again.</p>514504<h3 id="ServerResponse-redirect-url-status-">ServerResponse#redirect(url[, status])</h3>515<h3 id="Response-redirect-url-status-">Response#redirect(url[, status])</h3>516517<p>Redirect to the given <em>url</em> with a default response <em>status</em> of 302.</p>518519<pre><code>res.redirect('/', 301);
42 unmodified lines
modified:docs/guide.md+12 added-12 removed
153 unmodified lines
154 connect.logger(),155 connect.bodyDecoder()156 );157158### ServerRequest#header(key[, defaultValue])158### Request#header(key[, defaultValue])159160Get the case-insensitive request header _key_, with optional _defaultValue_:161162 req.header('Host');163 req.header('host');164 req.header('Accept', '*/*');165166### ServerRequest#accepts(type)166### Request#accepts(type)167168Check if the _Accept_ header is present, and includes the given _type_.169170When the _Accept_ header is not present _true_ is returned. Otherwise
15 unmodified lines
186 req.accepts('image/png');187 req.accepts('png');188 // => false189190### ServerRequest#param(name)190### Request#param(name)191192Return the value of param _name_ when present.193194 - Checks route placeholders, ex: /user/:id
3 unmodified lines
198To utilize urlencoded request bodies, _req.body_199should be an object. This can be done by using200the _connect.bodyDecoder_ middleware.201202### ServerRequest#flash(type[, msg])202### Request#flash(type[, msg])203204Queue flash _msg_ of the given _type_.205206 req.flash('info', 'email sent');
9 unmodified lines
216217 req.flash();218 // => { error: ['email delivery failed'], info: [] }219220### ServerRequest#isXMLHttpRequest220### Request#isXMLHttpRequest221222Also aliased as _req.xhr_, this getter checks the _X-Requested-With_ header223to see if it was issued by an _XMLHttpRequest_:224225 req.xhr226 req.isXMLHttpRequest227228### ServerResponse#header(key[, val])228### Response#header(key[, val])229230Get or set the response header _key_.231232 res.header('Content-Length');
4 unmodified lines
237238 res.header('Content-Length');239 // => 123240241### ServerResponse#contentType(type)241### Response#contentType(type)242243Sets the _Content-Type_ response header to the given _type_.244245 var filename = 'path/to/image.png';246 res.contentType(filename);247 // res.headers['Content-Type'] is now "image/png"248249### ServerResponse#attachment([filename])249### Response#attachment([filename])250251Sets the _Content-Disposition_ response header to "attachment", with optional _filename_.252253 res.attachment('path/to/my/image.png');254255### ServerResponse#sendfile(path)255### Response#sendfile(path)256257Used by `res.download()` to transfer an arbitrary file. 258259 res.sendfile('path/to/my.file');260261**NOTE**: this is _not_ a replacement for Connect's _staticProvider_ middleware,262nor does it perform any security checks, use with caution when using in a dynamic manor.263264### ServerResponse#download(file[, filename])264### Response#download(file[, filename])265266Transfer the given _file_ as an attachment with optional alternative _filename_.267268 res.download('path/to/image.png');
3 unmodified lines
272273 res.attachment(file);274 res.sendfile(file);275276### ServerRequest#send(body|status[, headers|status[, status]])276### Response#send(body|status[, headers|status[, status]])277278The `res.send()` method is a high level response utility allowing you to pass279objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status280code based responses. The following are all valid uses:
8 unmodified lines
289By default the _Content-Type_ response header is set, however if explicitly290assigned through `res.send()` or previously with `res.header()` or `res.contentType()`291it will not be set again.292293### ServerResponse#redirect(url[, status])293### Response#redirect(url[, status])294295Redirect to the given _url_ with a default response _status_ of 302.296297 res.redirect('/', 301);
32 unmodified lines
modified:docs/index.html+11 added
110 unmodified lines
111 margin: 0 auto;112 padding-top: 110px;113 width: 550px; }114115 #toc {116 position: fixed;117 top: 70px;118 left: 0;119 margin: 0 0 0 15px;120 padding: 0;121 }122 #toc li {123 list-style: none;124 }125126 #menu {127 margin-left: 65px;128 padding: 0;129 padding-bottom: 30px; }
92 unmodified lines
modified:docs/migrate.html+11 added
110 unmodified lines
111 margin: 0 auto;112 padding-top: 110px;113 width: 550px; }114115 #toc {116 position: fixed;117 top: 70px;118 left: 0;119 margin: 0 0 0 15px;120 padding: 0;121 }122 #toc li {123 list-style: none;124 }125126 #menu {127 margin-left: 65px;128 padding: 0;129 padding-bottom: 30px; }
262 unmodified lines