Skip to content
Myr

Toggling menus

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 3a7d5a0 · Browse files · 13 files+673 added−349 removed
This commit

State

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

Diff stats

13 files+673 added−349 removed

  • other:+673 added−349 removed

13 files+673 added−349 removed

modified:docs/layout/head.html+17 added
modified:docs/api.html+365 added-285 removed
158 unmodified lines
159 </p>160</td>161<td class="code">162<pre><code><span class="variable">require</span>(<span class="string">'./view'</span>);163<span class="variable">require</span>(<span class="string">'./request'</span>);163<span class="variable">require</span>(<span class="string">'./response'</span>);164<span class="variable">require</span>(<span class="string">'./request'</span>);165</code></pre>166</td>167</tr><tr class="filename"><td><h2 id="lib/express/request.js"><a href="#">request</a></h2></td><td>lib/express/request.js</td></tr><tr class="code">168<td class="docs">
7 unmodified lines
176</td>177</tr>178<tr class="code">179<td class="docs">180<p>Default flash formatters.</p>181182<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>183</td>184<td class="code">185<pre><code><span class="keyword">var</span> <span class="variable">flashFormatters</span> = <span class="variable">exports</span>.<span class="variable">flashFormatters</span> = {186 <span class="variable">s</span>: <span class="keyword">function</span>(<span class="variable">val</span>){187 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">val</span>);188 }189};</code></pre>190</td>191</tr>192<tr class="code">193<td class="docs">194<p>Return request header or optional default.</p>195196<h2>Examples</h2>197
126 unmodified lines
324325 req.flash();326 // =&gt; { error: ['email delivery failed'], info: [] }</code></pre>327328<h2>Formatting</h2>329330<p>Flash notifications also support arbitrary formatting support.331For example you may pass variable arguments to <code>req.flash()</code>332and use the %s specifier to be replaced by the associated argument:</p>333334<pre><code>req.flash('info', 'email has been sent to %s.', userName);</code></pre>335336<p>To add custom formatters use the <code>exports.flashFormatters</code> object.</p>337338<h2></h2>339340<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li><li><p><strong>return</strong>: <em>Array | Object | Number</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>341</td>342<td class="code">343<pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">flash</span> = <span class="keyword">function</span>(<span class="variable">type</span>, <span class="variable">msg</span>){344 <span class="keyword">var</span> <span class="variable">msgs</span> = <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> = <span class="this">this</span>.<span class="variable">session</span>.<span class="variable">flash</span> || {};345 <span class="keyword">if</span> (<span class="variable">type</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">msg</span>) {346 <span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">2</span>,347 <span class="variable">args</span> = <span class="variable">arguments</span>,348 <span class="variable">formatters</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">flashFormatters</span> || {};349 <span class="variable">formatters</span>.<span class="variable">__proto__</span> = <span class="variable">flashFormatters</span>;350 <span class="variable">msg</span> = <span class="variable">utils</span>.<span class="variable">miniMarkdown</span>(<span class="variable">utils</span>.<span class="variable">htmlEscape</span>(<span class="variable">msg</span>));351 <span class="variable">msg</span> = <span class="variable">msg</span>.<span class="variable">replace</span>(<span class="regexp">/%([a-zA-Z])/g</span>, <span class="keyword">function</span>(<span class="variable">_</span>, <span class="variable">format</span>){352 <span class="keyword">var</span> <span class="variable">formatter</span> = <span class="variable">formatters</span>[<span class="variable">format</span>];353 <span class="keyword">if</span> (<span class="variable">formatter</span>) <span class="keyword">return</span> <span class="variable">formatter</span>(<span class="variable">args</span>[<span class="variable">i</span>++]);354 });355 <span class="keyword">return</span> (<span class="variable">msgs</span>[<span class="variable">type</span>] = <span class="variable">msgs</span>[<span class="variable">type</span>] || []).<span class="variable">push</span>(<span class="variable">msg</span>);356 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">type</span>) {357 <span class="keyword">var</span> <span class="variable">arr</span> = <span class="variable">msgs</span>[<span class="variable">type</span>];358 <span class="keyword">delete</span> <span class="variable">msgs</span>[<span class="variable">type</span>];
22 unmodified lines
381<td class="code">382<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>);383<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>384</td>385</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">386<td class="docs">387<p>Module dependencies.388 </p>389</td>390<td class="code">391<pre><code><span class="keyword">var</span> <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>),392 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),393 <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),394 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),395 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,396 <span class="class">Buffer</span> = <span class="variable">require</span>(<span class="string">'buffer'</span>).<span class="class">Buffer</span>;</code></pre>397</td>398</tr>399<tr class="code">400<td class="docs">401<p>Header fields supporting multiple values.</p>402403<ul><li><p><strong>type</strong>: <em>Array</em></p></li></ul>404</td>405<td class="code">406<pre><code><span class="keyword">var</span> <span class="variable">multiple</span> = [<span class="string">'Set-Cookie'</span>];</code></pre>407</td>408</tr>409<tr class="code">410<td class="docs">411<p>Send a response with the given <code>body</code> and optional <code>headers</code> and <code>status</code> code.</p>412413<h2>Examples</h2>414415<pre><code>res.send();416res.send(new Buffer('wahoo'));417res.send({ some: 'json' });418res.send('&lt;p&gt;some html&lt;/p&gt;');419res.send('Sorry, cant find that', 404);420res.send('text', { 'Content-Type': 'text/plain' }, 201);421res.send(404);</code></pre>422423<h2></h2>424425<ul><li><p><strong>param</strong>: <em>String | Object | Number | Buffer</em> body or status</p></li><li><p><strong>param</strong>: <em>Object | Number</em> headers or status</p></li><li><p><strong>param</strong>: <em>Number</em> status</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>426</td>427<td class="code">428<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">send</span> = <span class="keyword">function</span>(<span class="variable">body</span>, <span class="variable">headers</span>, <span class="variable">status</span>){429 <span class="comment">// Allow status as second arg</span>430 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">headers</span> === <span class="string">'number'</span>) {431 <span class="variable">status</span> = <span class="variable">headers</span>,432 <span class="variable">headers</span> = <span class="keyword">null</span>;433 }434435 <span class="comment">// Defaults</span>436 <span class="variable">status</span> = <span class="variable">status</span> || <span class="number integer">200</span>;437438 <span class="comment">// Allow 0 args as 204</span>439 <span class="keyword">if</span> (!<span class="variable">arguments</span>.<span class="variable">length</span>) {440 <span class="variable">body</span> = <span class="variable">status</span> = <span class="number integer">204</span>;441 }442443 <span class="comment">// Determine content type</span>444 <span class="keyword">switch</span> (<span class="keyword">typeof</span> <span class="variable">body</span>) {445 <span class="keyword">case</span> <span class="string">'number'</span>:446 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {447 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.txt'</span>);448 }449 <span class="variable">body</span> = <span class="variable">http</span>.<span class="class">STATUS_CODES</span>[<span class="variable">status</span> = <span class="variable">body</span>];450 <span class="keyword">break</span>;451 <span class="keyword">case</span> <span class="string">'string'</span>:452 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {453 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.html'</span>);454 }455 <span class="keyword">break</span>;456 <span class="keyword">case</span> <span class="string">'object'</span>:457 <span class="keyword">if</span> (<span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>) {458 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {459 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.bin'</span>);460 }461 } <span class="keyword">else</span> {462 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {463 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.json'</span>);464 }465 <span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">stringify</span>(<span class="variable">body</span>);466 }467 <span class="keyword">break</span>;468 }469470 <span class="comment">// Populate Content-Length</span>471 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Length'</span>]) {472 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Length'</span>, <span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>473 ? <span class="variable">body</span>.<span class="variable">length</span>474 : <span class="class">Buffer</span>.<span class="variable">byteLength</span>(<span class="variable">body</span>));475 }476477 <span class="comment">// Merge headers passed</span>478 <span class="keyword">if</span> (<span class="variable">headers</span>) {479 <span class="keyword">var</span> <span class="variable">fields</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">headers</span>);480 <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">fields</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>) {481 <span class="keyword">var</span> <span class="variable">field</span> = <span class="variable">fields</span>[<span class="variable">i</span>];482 <span class="this">this</span>.<span class="variable">header</span>(<span class="variable">field</span>, <span class="variable">headers</span>[<span class="variable">field</span>]);483 }484 }485486 <span class="comment">// Strip irrelevant headers</span>487 <span class="keyword">if</span> (<span class="number integer">204</span> === <span class="variable">status</span>) {488 <span class="keyword">delete</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>];489 <span class="keyword">delete</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Length'</span>];490 }491492 <span class="comment">// Respond</span>493 <span class="this">this</span>.<span class="variable">writeHead</span>(<span class="variable">status</span>, <span class="this">this</span>.<span class="variable">headers</span>);494 <span class="this">this</span>.<span class="variable">end</span>(<span class="variable">body</span>);495};</code></pre>496</td>497</tr>498<tr class="code">499<td class="docs">500<p>Transfer the file at the given <code>path</code>. Automatically sets 501the <em>Content-Type</em> response header via <code>res.contentType()</code>. </p>502503<p>The given callback <code>fn</code> is invoked when an error occurs,504passing it as the first argument, or when the file is transferred,505passing the path as the second argument.</p>506507<h2></h2>508509<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>510</td>511<td class="code">512<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>){513 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;514 <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>){515 <span class="keyword">if</span> (<span class="variable">err</span>) {516 <span class="keyword">if</span> (<span class="variable">fn</span>) {517 <span class="variable">fn</span>(<span class="variable">err</span>, <span class="variable">path</span>);518 } <span class="keyword">else</span> {519 <span class="variable">self</span>.<span class="variable">req</span>.<span class="variable">next</span>(<span class="variable">err</span>);520 }521 } <span class="keyword">else</span> {522 <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">path</span>);523 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">buf</span>);524 <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>);525 }526 });527};</code></pre>528</td>529</tr>530<tr class="code">531<td class="docs">532<p>Set <em>Content-Type</em> response header passed through <code>mime.type()</code>.</p>533534<h2>Examples</h2>535536<pre><code>var filename = 'path/to/image.png';537res.contentType(filename);538// res.headers['Content-Type'] is now "image/png"</code></pre>539540<h2></h2>541542<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>return</strong>: <em>String</em> the resolved mime type</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>543</td>544<td class="code">545<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">contentType</span> = <span class="keyword">function</span>(<span class="variable">type</span>){546 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Type'</span>, <span class="variable">mime</span>.<span class="variable">type</span>(<span class="variable">type</span>));547};</code></pre>548</td>549</tr>550<tr class="code">551<td class="docs">552<p>Set <em>Content-Disposition</em> header to <em>attachment</em> with optional <code>filename</code>.</p>553554<h2></h2>555556<ul><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>557</td>558<td class="code">559<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">attachment</span> = <span class="keyword">function</span>(<span class="variable">filename</span>){560 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Disposition'</span>, <span class="variable">filename</span>561 ? <span class="string">'attachment; filename=&quot;'</span> + <span class="variable">path</span>.<span class="variable">basename</span>(<span class="variable">filename</span>) + <span class="string">'&quot;'</span>562 : <span class="string">'attachment'</span>);563 <span class="keyword">return</span> <span class="this">this</span>;564};</code></pre>565</td>566</tr>567<tr class="code">568<td class="docs">569<p>Transfer the file at the given <code>path</code>, with optional 570<code>filename</code> as an attachment. Once transferred, or if an571error occurs <code>fn</code> is called with the error and path.</p>572573<h2></h2>574575<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>576</td>577<td class="code">578<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>){579 <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>);580};</code></pre>581</td>582</tr>583<tr class="code">584<td class="docs">585<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>586587<p>Headers that may be set multiple times (as indicated by the <code>multiple</code> array)588can be called with a value several times, for example:</p>589590<p> res.header('Set-Cookie', '...');591 res.header('Set-Cookie', '...');</p>592593<h2></h2>594595<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>596</td>597<td class="code">598<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">name</span>, <span class="variable">val</span>){599 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {600 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>];601 } <span class="keyword">else</span> {602 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] &<span class="variable">amp</span>;&<span class="variable">amp</span>; ~<span class="variable">multiple</span>.<span class="variable">indexOf</span>(<span class="variable">name</span>)) {603 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] += <span class="string">'\r\n'</span> + <span class="variable">name</span> + <span class="string">': '</span> + <span class="variable">val</span>;604 } <span class="keyword">else</span> {605 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] = <span class="variable">val</span>;606 }607 }608};</code></pre>609</td>610</tr>611<tr class="code">612<td class="docs">613<p>Clear cookie <code>name</code>.</p>614615<h2></h2>616617<ul><li><p><strong>param</strong>: <em>String</em> name</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">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">clearCookie</span> = <span class="keyword">function</span>(<span class="variable">name</span>){621 <span class="this">this</span>.<span class="variable">cookie</span>(<span class="variable">name</span>, <span class="string">''</span>, { <span class="variable">expires</span>: <span class="keyword">new</span> <span class="class">Date</span>(<span class="number integer">1</span>) });622};</code></pre>623</td>624</tr>625<tr class="code">626<td class="docs">627<p>Set cookie <code>name</code> to <code>val</code>.</p>628629<h2>Examples</h2>630631<p> // "Remember Me" for 15 minutes632 res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });</p>633634<h2></h2>635636<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>param</strong>: <em>Options</em> options</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>637</td>638<td class="code">639<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">cookie</span> = <span class="keyword">function</span>(<span class="variable">name</span>, <span class="variable">val</span>, <span class="variable">options</span>){640 <span class="keyword">var</span> <span class="variable">cookie</span> = <span class="variable">utils</span>.<span class="variable">serializeCookie</span>(<span class="variable">name</span>, <span class="variable">val</span>, <span class="variable">options</span>);641 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Set-Cookie'</span>, <span class="variable">cookie</span>);642};</code></pre>643</td>644</tr>645<tr class="code">646<td class="docs">647<p>Redirect to the given <code>url</code> with optional response <code>status</code>648defauling to 302.</p>649650<p>The given <code>url</code> can also be the name of a mapped url, for651example by default express supports "back" which redirects652to the <em>Referrer</em> or <em>Referer</em> headers or the application's653"home" setting. Express also supports "home" out of the box,654which can be set via <code>app.set('home', '/blog');</code>, and defaults655to '/'.</p>656657<h2>Redirect Mapping</h2>658659<p> To extend the redirect mapping capabilities that Express provides,660 we may use the <code>app.redirect()</code> method:</p>661662<pre><code>app.redirect('google', 'http://google.com');</code></pre>663664<p> Now in a route we may call:</p>665666<pre><code>res.redirect('google');</code></pre>667668<p> We may also map dynamic redirects:</p>669670<pre><code> app.redirect('comments', function(req, res){671 return '/post/' + req.params.id + '/comments';672 });</code></pre>673674<p> So now we may do the following, and the redirect will dynamically adjust to675 the context of the request. If we called this route with <em>GET /post/12</em> our676 redirect <em>Location</em> would be <em>/post/12/comments</em>.</p>677678<pre><code> app.get('/post/:id', function(req, res){679 res.redirect('comments');680 });</code></pre>681682<h2></h2>683684<ul><li><p><strong>param</strong>: <em>String</em> url</p></li><li><p><strong>param</strong>: <em>Number</em> code</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>685</td>686<td class="code">687<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">redirect</span> = <span class="keyword">function</span>(<span class="variable">url</span>, <span class="variable">status</span>){688 <span class="keyword">var</span> <span class="variable">basePath</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>) || <span class="string">'/'</span>;689690 <span class="comment">// Setup redirect map</span>691 <span class="keyword">var</span> <span class="variable">map</span> = {692 <span class="variable">back</span>: <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referrer</span> || <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referer</span> || <span class="variable">basePath</span>,693 <span class="variable">home</span>: <span class="variable">basePath</span>694 };695696 <span class="comment">// Support custom redirect map</span>697 <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>;698699 <span class="comment">// Attempt mapped redirect</span>700 <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>701 ? <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>)702 : <span class="variable">map</span>[<span class="variable">url</span>];703704 <span class="comment">// Perform redirect</span>705 <span class="variable">url</span> = <span class="variable">mapped</span> || <span class="variable">url</span>;706707 <span class="comment">// Respond</span>708 <span class="this">this</span>.<span class="variable">send</span>(<span class="string">'Redirecting to '</span> + <span class="variable">url</span>, {709 <span class="string">'Content-Type'</span>: <span class="string">'text/plain'</span>,710 <span class="string">'Location'</span>: <span class="variable">url</span>711 }, <span class="variable">status</span> || <span class="number integer">302</span>);712};713</code></pre>714</td>715</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">716<td class="docs">717<p>Module dependencies.718 </p>
330 unmodified lines
1049 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;1050})(<span class="string">'get'</span>)(<span class="string">'post'</span>)(<span class="string">'put'</span>)(<span class="string">'del'</span>);1051</code></pre>1052</td>691</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">692<td class="docs">693<p>Module dependencies.694 </p>695</td>696<td class="code">697<pre><code><span class="keyword">var</span> <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>),698 <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),699 <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),700 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),701 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,702 <span class="class">Buffer</span> = <span class="variable">require</span>(<span class="string">'buffer'</span>).<span class="class">Buffer</span>;</code></pre>703</td>704</tr>705<tr class="code">706<td class="docs">707<p>Header fields supporting multiple values.</p>708709<ul><li><p><strong>type</strong>: <em>Array</em></p></li></ul>710</td>711<td class="code">712<pre><code><span class="keyword">var</span> <span class="variable">multiple</span> = [<span class="string">'Set-Cookie'</span>];</code></pre>713</td>714</tr>715<tr class="code">716<td class="docs">717<p>Send a response with the given <code>body</code> and optional <code>headers</code> and <code>status</code> code.</p>718719<h2>Examples</h2>720721<pre><code>res.send(new Buffer('wahoo'));722res.send({ some: 'json' });723res.send('&lt;p&gt;some html&lt;/p&gt;');724res.send('Sorry, cant find that', 404);725res.send('text', { 'Content-Type': 'text/plain' }, 201);726res.send(404);</code></pre>727728<h2></h2>729730<ul><li><p><strong>param</strong>: <em>String | Object | Number | Buffer</em> body or status</p></li><li><p><strong>param</strong>: <em>Object | Number</em> headers or status</p></li><li><p><strong>param</strong>: <em>Number</em> status</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>731</td>732<td class="code">733<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">send</span> = <span class="keyword">function</span>(<span class="variable">body</span>, <span class="variable">headers</span>, <span class="variable">status</span>){734 <span class="comment">// Allow status as second arg</span>735 <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">headers</span> === <span class="string">'number'</span>) {736 <span class="variable">status</span> = <span class="variable">headers</span>,737 <span class="variable">headers</span> = <span class="keyword">null</span>;738 }739740 <span class="comment">// Defaults</span>741 <span class="variable">status</span> = <span class="variable">status</span> || <span class="number integer">200</span>;742743 <span class="comment">// Determine content type</span>744 <span class="keyword">switch</span> (<span class="keyword">typeof</span> <span class="variable">body</span>) {745 <span class="keyword">case</span> <span class="string">'number'</span>:746 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {747 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.txt'</span>);748 }749 <span class="variable">body</span> = <span class="variable">http</span>.<span class="class">STATUS_CODES</span>[<span class="variable">status</span> = <span class="variable">body</span>];750 <span class="keyword">break</span>;751 <span class="keyword">case</span> <span class="string">'string'</span>:752 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {753 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.html'</span>);754 }755 <span class="keyword">break</span>;756 <span class="keyword">case</span> <span class="string">'object'</span>:757 <span class="keyword">if</span> (<span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>) {758 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {759 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.bin'</span>);760 }761 } <span class="keyword">else</span> {762 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Type'</span>]) {763 <span class="this">this</span>.<span class="variable">contentType</span>(<span class="string">'.json'</span>);764 }765 <span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">stringify</span>(<span class="variable">body</span>);766 }767 <span class="keyword">break</span>;768 }769770 <span class="comment">// Populate Content-Length</span>771 <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">headers</span>[<span class="string">'Content-Length'</span>]) {772 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Length'</span>, <span class="variable">body</span> <span class="variable">instanceof</span> <span class="class">Buffer</span>773 ? <span class="variable">body</span>.<span class="variable">length</span>774 : <span class="class">Buffer</span>.<span class="variable">byteLength</span>(<span class="variable">body</span>));775 }776777 <span class="comment">// Merge headers passed</span>778 <span class="keyword">if</span> (<span class="variable">headers</span>) {779 <span class="keyword">var</span> <span class="variable">fields</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">headers</span>);780 <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">fields</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>) {781 <span class="keyword">var</span> <span class="variable">field</span> = <span class="variable">fields</span>[<span class="variable">i</span>];782 <span class="this">this</span>.<span class="variable">header</span>(<span class="variable">field</span>, <span class="variable">headers</span>[<span class="variable">field</span>]);783 }784 }785786 <span class="comment">// Respond</span>787 <span class="this">this</span>.<span class="variable">writeHead</span>(<span class="variable">status</span>, <span class="this">this</span>.<span class="variable">headers</span>);788 <span class="this">this</span>.<span class="variable">end</span>(<span class="variable">body</span>);789};</code></pre>790</td>791</tr>792<tr class="code">793<td class="docs">794<p>Transfer the file at the given <code>path</code>. Automatically sets 795the <em>Content-Type</em> response header via <code>res.contentType()</code>. </p>796797<p>The given callback <code>fn</code> is invoked when an error occurs,798passing it as the first argument, or when the file is transferred,799passing the path as the second argument.</p>800801<h2></h2>802803<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>804</td>805<td class="code">806<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>){807 <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;808 <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>){809 <span class="keyword">if</span> (<span class="variable">err</span>) {810 <span class="keyword">if</span> (<span class="variable">fn</span>) {811 <span class="variable">fn</span>(<span class="variable">err</span>, <span class="variable">path</span>);812 } <span class="keyword">else</span> {813 <span class="variable">self</span>.<span class="variable">req</span>.<span class="variable">next</span>(<span class="variable">err</span>);814 }815 } <span class="keyword">else</span> {816 <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">path</span>);817 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">buf</span>);818 <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>);819 }820 });821};</code></pre>822</td>823</tr>824<tr class="code">825<td class="docs">826<p>Set <em>Content-Type</em> response header passed through <code>mime.type()</code>.</p>827828<h2>Examples</h2>829830<pre><code>var filename = 'path/to/image.png';831res.contentType(filename);832// res.headers['Content-Type'] is now "image/png"</code></pre>833834<h2></h2>835836<ul><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>return</strong>: <em>String</em> the resolved mime type</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>837</td>838<td class="code">839<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">contentType</span> = <span class="keyword">function</span>(<span class="variable">type</span>){840 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Type'</span>, <span class="variable">mime</span>.<span class="variable">type</span>(<span class="variable">type</span>));841};</code></pre>842</td>843</tr>844<tr class="code">845<td class="docs">846<p>Set <em>Content-Disposition</em> header to <em>attachment</em> with optional <code>filename</code>.</p>847848<h2></h2>849850<ul><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>ServerResponse</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>851</td>852<td class="code">853<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">attachment</span> = <span class="keyword">function</span>(<span class="variable">filename</span>){854 <span class="this">this</span>.<span class="variable">header</span>(<span class="string">'Content-Disposition'</span>, <span class="variable">filename</span>855 ? <span class="string">'attachment; filename=&quot;'</span> + <span class="variable">path</span>.<span class="variable">basename</span>(<span class="variable">filename</span>) + <span class="string">'&quot;'</span>856 : <span class="string">'attachment'</span>);857 <span class="keyword">return</span> <span class="this">this</span>;858};</code></pre>859</td>860</tr>861<tr class="code">862<td class="docs">863<p>Transfer the file at the given <code>path</code>, with optional 864<code>filename</code> as an attachment. Once transferred, or if an865error occurs <code>fn</code> is called with the error and path.</p>866867<h2></h2>868869<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>870</td>871<td class="code">872<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>){873 <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>);874};</code></pre>875</td>876</tr>877<tr class="code">878<td class="docs">879<p>Set or get response header <code>name</code> with optional <code>val</code>.</p>880881<p>Headers that may be set multiple times (as indicated by the <code>multiple</code> array)882can be called with a value several times, for example:</p>883884<p> res.header('Set-Cookie', '...');885 res.header('Set-Cookie', '...');</p>886887<h2></h2>888889<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>890</td>891<td class="code">892<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">name</span>, <span class="variable">val</span>){893 <span class="keyword">if</span> (<span class="variable">val</span> === <span class="variable">undefined</span>) {894 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>];895 } <span class="keyword">else</span> {896 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] &<span class="variable">amp</span>;&<span class="variable">amp</span>; ~<span class="variable">multiple</span>.<span class="variable">indexOf</span>(<span class="variable">name</span>)) {897 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] += <span class="string">'\r\n'</span> + <span class="variable">name</span> + <span class="string">': '</span> + <span class="variable">val</span>;898 } <span class="keyword">else</span> {899 <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">headers</span>[<span class="variable">name</span>] = <span class="variable">val</span>;900 }901 }902};</code></pre>903</td>904</tr>905<tr class="code">906<td class="docs">907<p>Redirect to the given <code>url</code> with optional response <code>status</code>908defauling to 302.</p>909910<p>The given <code>url</code> can also be the name of a mapped url, for911example by default express supports "back" which redirects912to the <em>Referrer</em> or <em>Referer</em> headers or the application's913"home" setting. Express also supports "home" out of the box,914which can be set via <code>app.set('home', '/blog');</code>, and defaults915to '/'.</p>916917<h2>Redirect Mapping</h2>918919<p> To extend the redirect mapping capabilities that Express provides,920 we may use the <code>app.redirect()</code> method:</p>921922<pre><code>app.redirect('google', 'http://google.com');</code></pre>923924<p> Now in a route we may call:</p>925926<pre><code>res.redirect('google');</code></pre>927928<p> We may also map dynamic redirects:</p>929930<pre><code> app.redirect('comments', function(req, res){931 return '/post/' + req.params.id + '/comments';932 });</code></pre>933934<p> So now we may do the following, and the redirect will dynamically adjust to935 the context of the request. If we called this route with <em>GET /post/12</em> our936 redirect <em>Location</em> would be <em>/post/12/comments</em>.</p>937938<pre><code> app.get('/post/:id', function(req, res){939 res.redirect('comments');940 });</code></pre>941942<h2></h2>943944<ul><li><p><strong>param</strong>: <em>String</em> url</p></li><li><p><strong>param</strong>: <em>Number</em> code</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>945</td>946<td class="code">947<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">redirect</span> = <span class="keyword">function</span>(<span class="variable">url</span>, <span class="variable">status</span>){948 <span class="keyword">var</span> <span class="variable">basePath</span> = <span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'home'</span>) || <span class="string">'/'</span>;949950 <span class="comment">// Setup redirect map</span>951 <span class="keyword">var</span> <span class="variable">map</span> = {952 <span class="variable">back</span>: <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referrer</span> || <span class="this">this</span>.<span class="variable">req</span>.<span class="variable">headers</span>.<span class="variable">referer</span> || <span class="variable">basePath</span>,953 <span class="variable">home</span>: <span class="variable">basePath</span>954 };955956 <span class="comment">// Support custom redirect map</span>957 <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>;958959 <span class="comment">// Attempt mapped redirect</span>960 <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>961 ? <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>)962 : <span class="variable">map</span>[<span class="variable">url</span>];963964 <span class="comment">// Perform redirect</span>965 <span class="variable">url</span> = <span class="variable">mapped</span> || <span class="variable">url</span>;966 <span class="this">this</span>.<span class="variable">send</span>(<span class="string">'Redirecting to '</span> + <span class="variable">url</span>, {967 <span class="string">'Content-Type'</span>: <span class="string">'text/plain'</span>,968 <span class="string">'Location'</span>: <span class="variable">url</span>969 }, <span class="variable">status</span> || <span class="number integer">302</span>);970};971</code></pre>972</td>1053</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">1054<td class="docs">1055<p>Parse mini markdown implementation.1056The following conversions are supported,
175 unmodified lines
12321233<p> Most engines accept one or more of the following options,1234 both <em>haml</em> and <em>jade</em> accept all:</p>12351156<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>1236<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><li><code>status</code> Response status code, defaults to 200</li><li><code>headers</code> Response headers object</li></ul>12371238<h2></h2>12391240<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>
116 unmodified lines
1357 <span class="keyword">return</span> <span class="variable">str</span>;1358 } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">fn</span>) {1359 <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">str</span>);1360 } <span class="keyword">else</span> {1281 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">str</span>);1361 <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">str</span>, <span class="variable">options</span>.<span class="variable">headers</span>, <span class="variable">options</span>.<span class="variable">status</span>);1362 }1363};1364</code></pre>1365</td>
2 unmodified lines
modified:docs/contrib.1+5 added-2 removed
1.\" generated with Ronn/v0.6.62.\" http://github.com/rtomayko/ronn/1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "CONTRIB" "" "July 2010" "" ""5.6.SH "NAME"7\fBcontrib\fR8.9.SS "Development Dependencies"10Express development dependencies are stored within the \fI\./support\fR directory\. To update them execute:11.12.IP "" 4
70 unmodified lines
modified:docs/contrib.html+21 added
1<html>2 <head>3 <title>Express - node web framework</title>4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>5 <style>6 #tagline {7 margin-left: 75px;8 margin-bottom: 30px;
58 unmodified lines
67 ul li {68 margin: 0;69 padding: 2px 0;70 list-style: square; }71 ul li ul {72 margin: 0;73 padding-left: 12px;74 }7576 .sect {77 margin-left: 40px; }78
71 unmodified lines
150 background: rgba(0,0,0,0.1);151 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);152 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }153 </style>154 <script>155 $(function(){156 $('.section').hide();157 $('.toggle, a.section-title').toggle(function(){158 $(this).siblings('ul').fadeIn(300);159 return false;160 }, function(){161 $(this).siblings('ul').fadeOut(300);162 return false;163 });164 });165 </script>166 </head>167 <body>168 <a href='http://github.com/visionmedia/express'> 169 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' />
11 unmodified lines
181 <li><a href="contrib.html">Contributing</a></li>182 <li><a href="migrate.html">1.x Migration</a></li>183 </ul>184<div class='mp'>185<h2 id="Express">Express</h2>186<p class="man-name">187 <code>contrib</code>188</p>189<h3 id="Development-Dependencies">Development Dependencies</h3>190191<p>Express development dependencies are stored within the <em>./support</em> directory. To192update them execute:</p>
46 unmodified lines
modified:docs/executable.1+5 added-2 removed
1.\" generated with Ronn/v0.6.62.\" http://github.com/rtomayko/ronn/1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "EXECUTABLE" "" "July 2010" "" ""5.6.SH "NAME"7\fBexecutable\fR8.9.SH "Synopsis"10.11.nf12
16 unmodified lines
modified:docs/executable.html+21 added
1<html>2 <head>3 <title>Express - node web framework</title>4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>5 <style>6 #tagline {7 margin-left: 75px;8 margin-bottom: 30px;
58 unmodified lines
67 ul li {68 margin: 0;69 padding: 2px 0;70 list-style: square; }71 ul li ul {72 margin: 0;73 padding-left: 12px;74 }7576 .sect {77 margin-left: 40px; }78
71 unmodified lines
150 background: rgba(0,0,0,0.1);151 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);152 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }153 </style>154 <script>155 $(function(){156 $('.section').hide();157 $('.toggle, a.section-title').toggle(function(){158 $(this).siblings('ul').fadeIn(300);159 return false;160 }, function(){161 $(this).siblings('ul').fadeOut(300);162 return false;163 });164 });165 </script>166 </head>167 <body>168 <a href='http://github.com/visionmedia/express'> 169 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' />
11 unmodified lines
181 <li><a href="contrib.html">Contributing</a></li>182 <li><a href="migrate.html">1.x Migration</a></li>183 </ul>184<div class='mp'>185<h2 id="Express">Express</h2>186<p class="man-name">187 <code>executable</code>188</p>189<h2 id="Synopsis">Synopsis</h2>190191<pre><code>express [-h|--help] [-v|--version] [PATH]192</code></pre>
18 unmodified lines
modified:docs/guide.1+96 added-29 removed
1.\" generated with Ronn/v0.6.62.\" http://github.com/rtomayko/ronn/1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "GUIDE" "" "August 2010" "" ""4.TH "GUIDE" "" "September 2010" "" ""5.6.SH "NAME"7\fBguide\fR8.9.SS "Installation"10curl:11.12.IP "" 4
91 unmodified lines
104105app\.configure(function(){106 app\.set(\'views\', __dirname + \'/views\');107 app\.set(\'views\');105 // => \"\.\.\. views directory \.\.\.\"108 // => "\.\.\. views directory \.\.\."109110 app\.enable(\'some feature\');111 // same as app\.set(\'some feature\', true);112
62 unmodified lines
175.IP "" 4176.177.nf178176\\/user\\/([^\\/]+)\\/?179\e/user\e/([^\e/]+)\e/?180.181.fi182.183.IP "" 0
4 unmodified lines
188.IP "" 4189.190.nf191189app\.get(/^\\/users?(?:\\/(\\d+)(?:\\\.\\\.(\\d+))?)?/, function(req, res){192app\.get(/^\e/users?(?:\e/(\ed+)(?:\e\.\e\.(\ed+))?)?/, function(req, res){193 res\.send(req\.params);194});195.196.fi
11 unmodified lines
208 [null,null]209 $ curl http://dev:3000/users210 [null,null]211 $ curl http://dev:3000/users/1209 [\"1\",null]212 ["1",null]213 $ curl http://dev:3000/users/1\.\.15211 [\"1\",\"15\"]214 ["1","15"]215.216.fi217.218.IP "" 0
4 unmodified lines
223.IP "" 4224.225.nf226224 \"/user/:id\"227 "/user/:id"228 /user/12229227 \"/users/:id?\"230 "/users/:id?"231 /users/5232 /users233231 \"/files/*\"234 "/files/*"235 /files/jquery\.js236 /files/javascripts/jquery\.js237235 \"/file/*\.*\"238 "/file/*\.*"239 /files/jquery\.js240 /files/javascripts/jquery\.js241239 \"/user/:id/:operation?\"242 "/user/:id/:operation?"243 /user/1244 /user/1/edit245243 \"/products\.:format\"246 "/products\.:format"247 /products\.json248 /products\.xml249247 \"/products\.:format?\"250 "/products\.:format?"251 /products\.json252 /products\.xml253 /products254.
25 unmodified lines
280.281.IP "" 0282.283.SS "Middleware"281The Express \fIPlugin\fR is no more! middleware via Connect \fIhttp://github\.com/extjs/Connect\fR can be passed to \fIexpress\.createServer()\fR as you would with a regular Connect server\. For example:284The Express \fIPlugin\fR is no more! middleware via Connect \fIhttp://github\.com/senchalabs/connect\fR can be passed to \fIexpress\.createServer()\fR as you would with a regular Connect server\. For example:285.286.IP "" 4287.288.nf
117 unmodified lines
406.407.IP "" 0408.409.P407Our apps could also utilize the Connect \fIerrorHandler\fR middleware to report on exceptions\. For example if we wish to output exceptions in \"development\" mode to \fIstderr\fR we can use:410Our apps could also utilize the Connect \fIerrorHandler\fR middleware to report on exceptions\. For example if we wish to output exceptions in "development" mode to \fIstderr\fR we can use:411.412.IP "" 4413.414.nf
20 unmodified lines
435.P436The \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\.437.438.SS "View Rendering"436View 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\.439View 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\.440.441.P442Below 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\.443.
107 unmodified lines
551.552.IP "" 0553.554.SS "View Partials"552The 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:555The 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:556.557.IP "" 4558.559.nf
30 unmodified lines
590.591.IP "" 0592.593.P591When using the partial collection support a few \"magic\" variables are provided for free:594When using the partial collection support a few "magic" variables are provided for free:595.596.IP "\(bu" 4597\fIfirstInCollection\fR True if this is the first object598.
37 unmodified lines
636.SS "req\.accepts(type)"637Check if the \fIAccept\fR header is present, and includes the given \fItype\fR\.638.639.P637When 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\.640When 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\.641.642.IP "" 4643.644.nf
58 unmodified lines
703.fi704.705.IP "" 0706.707.P708Flash notification message may also utilize formatters, by default only the %s string formatter is available:709.710.IP "" 4711.712.nf713714req\.flash(\'info\', \'email delivery to _%s_ from _%s_ failed\.\', toUser, fromUser);715.716.fi717.718.IP "" 0719.720.SS "req\.isXMLHttpRequest"721Also aliased as \fIreq\.xhr\fR, this getter checks the \fIX\-Requested\-With\fR header to see if it was issued by an \fIXMLHttpRequest\fR:722.723.IP "" 4
35 unmodified lines
759.nf760761 var filename = \'path/to/image\.png\';762 res\.contentType(filename);747 // res\.headers[\'Content\-Type\'] is now \"image/png\"763 // res\.headers[\'Content\-Type\'] is now "image/png"764.765.fi766.767.IP "" 0768.769.SS "res\.attachment([filename])"754Sets the \fIContent\-Disposition\fR response header to \"attachment\", with optional \fIfilename\fR\.770Sets the \fIContent\-Disposition\fR response header to "attachment", with optional \fIfilename\fR\.771.772.IP "" 4773.774.nf
54 unmodified lines
829.IP "" 4830.831.nf832833 res\.send(); // 204834 res\.send(new Buffer(\'wahoo\'));835 res\.send({ some: \'json\' });836 res\.send(\'<p>some html</p>\');837 res\.send(\'Sorry, cant find that\', 404);
24 unmodified lines
862.863.IP "" 0864.865.P849Express supports \"redirect mapping\", which by default provides \fIhome\fR, and \fIback\fR\. The \fIback\fR map checks the \fIReferrer\fR and \fIReferer\fR headers, while \fIhome\fR utilizes the \"home\" setting and defaults to \"/\"\.866Express supports "redirect mapping", which by default provides \fIhome\fR, and \fIback\fR\. The \fIback\fR map checks the \fIReferrer\fR and \fIReferer\fR headers, while \fIhome\fR utilizes the "home" setting and defaults to "/"\.867.868.SS "res\.cookie(name, val[, options])"869Sets the given cookie \fIname\fR to \fIval\fR, with \fIoptions\fR such as "httpOnly: true", "expires", "secure" etc\.870.871.IP "" 4872.873.nf874875// "Remember me" for 15 minutes876res\.cookie(\'rememberme\', \'yes\', { expires: new Date(Date\.now() + 900000), httpOnly: true });877.878.fi879.880.IP "" 0881.882.P883To parse incoming \fICookie\fR headers, use the \fIcookieDecoder\fR middleware, which provides the \fIreq\.cookies\fR object:884.885.IP "" 4886.887.nf888889app\.use(express\.cookieDecoder());890891app\.get(\'/\', function(req, res){892 // use req\.cookies\.rememberme893});894.895.fi896.897.IP "" 0898.899.SS "res\.clearCookie(name)"900Clear cookie \fIname\fR by setting "expires" far in the past\.901.902.IP "" 4903.904.nf905906res\.clearCookie(\'rememberme\');907.908.fi909.910.IP "" 0911.912.SS "res\.render(view[, options[, fn]])"913Render \fIview\fR with the given \fIoptions\fR and optional callback \fIfn\fR\. When a callback function is given a response will \fInot\fR be made automatically, however otherwise a response of \fI200\fR and \fItext/html\fR is given\.914.915.P
7 unmodified lines
923.924.IP "\(bu" 4925\fIdebug\fR Output debugging information926.927.IP "\(bu" 4928\fIstatus\fR Response status code, defaults to 200929.930.IP "\(bu" 4931\fIheaders\fR Response headers object932.933.IP "" 0934.935.SS "res\.partial(view[, options])"936Render \fIview\fR partial with the given \fIoptions\fR\. This method is always available to the view as a local variable\.
34 unmodified lines
971.972.IP "" 0973.974.P908To change the local from \fImovie\fR to \fIvideo\fR we can use the \"as\" option:975To change the local from \fImovie\fR to \fIvideo\fR we can use the "as" option:976.977.IP "" 4978.979.nf
19 unmodified lines
999.1000.IP "" 01001.1002.P936Another alternative is to \"explode\" the properties of the collection item into pseudo globals (local variables) by using \fIas: global\fR, which again is syntactic sugar:1003Another alternative is to "explode" the properties of the collection item into pseudo globals (local variables) by using \fIas: global\fR, which again is syntactic sugar:1004.1005.IP "" 41006.1007.nf
204 unmodified lines
1212 blog = express\.createServer();12131214blog\.mounted(function(parent){1215 // parent is app1149 // \"this\" is blog1216 // "this" is blog1217});12181219app\.use(blog);1220.
1 unmodified line
1222.1223.IP "" 01224.1225.SS "app\.register(ext, exports)"1159Register the given template engine \fIexports\fR as \fIext\fR\. For example we may wish to map \"\.html\" files to jade:1226Register the given template engine \fIexports\fR as \fIext\fR\. For example we may wish to map "\.html" files to jade:1227.1228.IP "" 41229.1230.nf
4 unmodified lines
1235.1236.IP "" 01237.1238.P1172This 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\":1239This 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":1240.1241.IP "" 41242.1243.nf
73 unmodified lines
modified:docs/guide.html+88 added-27 removed
1<html>2 <head>3 <title>Express - node web framework</title>4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>5 <style>6 #tagline {7 margin-left: 75px;8 margin-bottom: 30px;
58 unmodified lines
67 ul li {68 margin: 0;69 padding: 2px 0;70 list-style: square; }71 ul li ul {72 margin: 0;73 padding-left: 12px;74 }7576 .sect {77 margin-left: 40px; }78
71 unmodified lines
150 background: rgba(0,0,0,0.1);151 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);152 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }153 </style>154 <script>155 $(function(){156 $('.section').hide();157 $('.toggle, a.section-title').toggle(function(){158 $(this).siblings('ul').fadeIn(300);159 return false;160 }, function(){161 $(this).siblings('ul').fadeOut(300);162 return false;163 });164 });165 </script>166 </head>167 <body>168 <a href='http://github.com/visionmedia/express'> 169 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' />
10 unmodified lines
180<li><a href="#Error-Handling">Error Handling</a></li>181<li><a href="#View-Rendering">View Rendering</a></li>182<li><a href="#View-Partials">View Partials</a></li>183<li><a href="#Template-Engines">Template Engines</a></li>167<li><a href="#req-header-key-defaultValue-">req.header()</a></li>168<li><a href="#req-accepts-type-">req.accepts()</a></li>169<li><a href="#req-param-name-">req.param()</a></li>170<li><a href="#req-flash-type-msg-">req.flash()</a></li>171<li><a href="#req-isXMLHttpRequest">req.isXMLHttpRequest</a></li>172<li><a href="#res-header-key-val-">res.header()</a></li>173<li><a href="#res-contentType-type-">res.contentType()</a></li>174<li><a href="#res-attachment-filename-">res.attachment()</a></li>175<li><a href="#res-sendfile-path-">res.sendfile()</a></li>176<li><a href="#res-download-file-filename-">res.download()</a></li>177<li><a href="#res-send-body-status-headers-status-status-">res.send()</a></li>178<li><a href="#res-redirect-url-status-">res.redirect()</a></li>179<li><a href="#res-render-view-options-fn-">res.render()</a></li>180<li><a href="#res-partial-view-options-">res.partial()</a></li>181<li><a href="#app-set-name-val-">app.set()</a></li>182<li><a href="#app-enable-name-">app.enable()</a></li>183<li><a href="#app-disable-name-">app.disable()</a></li>184<li><a href="#app-configure-env-function-function-">app.configure()</a></li>185<li><a href="#app-redirect-name-val-">app.redirect()</a></li>186<li><a href="#app-error-function-">app.error()</a></li>187<li><a href="#app-helpers-obj-">app.helpers()</a></li>188<li><a href="#app-dynamicHelpers-obj-">app.dynamicHelpers()</a></li>189<li><a href="#app-mounted-fn-">app.mounted()</a></li>190<li><a href="#app-register-ext-exports-">app.register()</a></li>191<li><a href="#app-listen-port-host-">app.listen()</a></li>184<li><a href="#" class="toggle">+</a> <a class="section-title" href="#">Request</a><ul class="section" id="section-Request">185<li><a href="#req-header-key-defaultValue-">header()</a></li>186<li><a href="#req-accepts-type-">accepts()</a></li>187<li><a href="#req-param-name-">param()</a></li>188<li><a href="#req-flash-type-msg-">flash()</a></li>189<li><a href="#req-isXMLHttpRequest">isXMLHttpRequest</a></li>190</ul></li>191<li><a href="#" class="toggle">+</a> <a class="section-title" href="#">Response</a><ul class="section" id="section-Response">192<li><a href="#res-header-key-val-">header()</a></li>193<li><a href="#res-contentType-type-">contentType()</a></li>194<li><a href="#res-attachment-filename-">attachment()</a></li>195<li><a href="#res-sendfile-path-">sendfile()</a></li>196<li><a href="#res-download-file-filename-">download()</a></li>197<li><a href="#res-send-body-status-headers-status-status-">send()</a></li>198<li><a href="#res-redirect-url-status-">redirect()</a></li>199<li><a href="#res-cookie-name-val-options-">cookie()</a></li>200<li><a href="#res-clearCookie-name-">clearCookie()</a></li>201<li><a href="#res-render-view-options-fn-">render()</a></li>202<li><a href="#res-partial-view-options-">partial()</a></li>203</ul></li>204<li><a href="#" class="toggle">+</a> <a class="section-title" href="#">Server</a><ul class="section" id="section-Server">205<li><a href="#app-set-name-val-">set()</a></li>206<li><a href="#app-enable-name-">enable()</a></li>207<li><a href="#app-disable-name-">disable()</a></li>208<li><a href="#app-configure-env-function-function-">configure()</a></li>209<li><a href="#app-redirect-name-val-">redirect()</a></li>210<li><a href="#app-error-function-">error()</a></li>211<li><a href="#app-helpers-obj-">helpers()</a></li>212<li><a href="#app-dynamicHelpers-obj-">dynamicHelpers()</a></li>213<li><a href="#app-mounted-fn-">mounted()</a></li>214<li><a href="#app-register-ext-exports-">register()</a></li>215<li><a href="#app-listen-port-host-">listen()</a></li>216</ul></li>217</ul>218 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 219 <p id="tagline">220 High performance, high class web development for
5 unmodified lines
226 <li><a href="contrib.html">Contributing</a></li>227 <li><a href="migrate.html">1.x Migration</a></li>228 </ul>229<div class='mp'>230<h2 id="Express">Express</h2>231<p class="man-name">232 <code>guide</code>233</p>234<h3 id="Installation">Installation</h3>235236<p>curl:</p>237
181 unmodified lines
419</code></pre>420421<h3 id="Middleware">Middleware</h3>422394<p>The Express <em>Plugin</em> is no more! middleware via <a href="http://github.com/extjs/Connect">Connect</a> can be423<p>The Express <em>Plugin</em> is no more! middleware via <a href="http://github.com/senchalabs/connect">Connect</a> can be424passed to <em>express.createServer()</em> as you would with a regular Connect server. For example:</p>425426<pre><code>var express = require('express');427
257 unmodified lines
685req.flash();686// =&gt; { error: ['email delivery failed'], info: [] }687</code></pre>688689<p>Flash notification message may also utilize formatters, by default only the %s string formatter is available:</p>690691<pre><code>req.flash('info', 'email delivery to _%s_ from _%s_ failed.', toUser, fromUser);692</code></pre>693694<h3 id="req-isXMLHttpRequest">req.isXMLHttpRequest</h3>695696<p>Also aliased as <em>req.xhr</em>, this getter checks the <em>X-Requested-With</em> header697to see if it was issued by an <em>XMLHttpRequest</em>:</p>
63 unmodified lines
761<p>The <code>res.send()</code> method is a high level response utility allowing you to pass762objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status763code based responses. The following are all valid uses:</p>764731<pre><code> res.send(new Buffer('wahoo'));765<pre><code> res.send(); // 204766 res.send(new Buffer('wahoo'));767 res.send({ some: 'json' });768 res.send('&lt;p&gt;some html&lt;/p&gt;');769 res.send('Sorry, cant find that', 404);770 res.send('text', { 'Content-Type': 'text/plain' }, 201);
18 unmodified lines
789<p>Express supports "redirect mapping", which by default provides <em>home</em>, and <em>back</em>.790The <em>back</em> map checks the <em>Referrer</em> and <em>Referer</em> headers, while <em>home</em> utilizes791the "home" setting and defaults to "/".</p>792793<h3 id="res-cookie-name-val-options-">res.cookie(name, val[, options])</h3>794795<p>Sets the given cookie <em>name</em> to <em>val</em>, with <em>options</em> such as "httpOnly: true", "expires", "secure" etc.</p>796797<pre><code>// "Remember me" for 15 minutes 798res.cookie('rememberme', 'yes', { expires: new Date(Date.now() + 900000), httpOnly: true });799</code></pre>800801<p>To parse incoming <em>Cookie</em> headers, use the <em>cookieDecoder</em> middleware, which provides the <em>req.cookies</em> object:</p>802803<pre><code>app.use(express.cookieDecoder());804805app.get('/', function(req, res){806 // use req.cookies.rememberme807});808</code></pre>809810<h3 id="res-clearCookie-name-">res.clearCookie(name)</h3>811812<p>Clear cookie <em>name</em> by setting "expires" far in the past.</p>813814<pre><code>res.clearCookie('rememberme');815</code></pre>816817<h3 id="res-render-view-options-fn-">res.render(view[, options[, fn]])</h3>818819<p>Render <em>view</em> with the given <em>options</em> and optional callback <em>fn</em>.820When a callback function is given a response will <em>not</em> be made
5 unmodified lines
826<ul>827<li><em>context|scope</em> Template evaluation context (<em>this</em>)</li>828<li><em>locals</em> Object containing local variables</li>829<li><em>debug</em> Output debugging information</li>830<li><em>status</em> Response status code, defaults to 200</li>831<li><em>headers</em> Response headers object</li>832</ul>833834835<h3 id="res-partial-view-options-">res.partial(view[, options])</h3>
237 unmodified lines
modified:docs/index.1+5 added-2 removed
1.\" generated with Ronn/v0.6.62.\" http://github.com/rtomayko/ronn/1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "INDEX" "" "August 2010" "" ""5.6.SH "NAME"7\fBindex\fR8.9.IP "" 410.11.nf12
122 unmodified lines
modified:docs/index.html+21 added
1<html>2 <head>3 <title>Express - node web framework</title>4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>5 <style>6 #tagline {7 margin-left: 75px;8 margin-bottom: 30px;
58 unmodified lines
67 ul li {68 margin: 0;69 padding: 2px 0;70 list-style: square; }71 ul li ul {72 margin: 0;73 padding-left: 12px;74 }7576 .sect {77 margin-left: 40px; }78
71 unmodified lines
150 background: rgba(0,0,0,0.1);151 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);152 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }153 </style>154 <script>155 $(function(){156 $('.section').hide();157 $('.toggle, a.section-title').toggle(function(){158 $(this).siblings('ul').fadeIn(300);159 return false;160 }, function(){161 $(this).siblings('ul').fadeOut(300);162 return false;163 });164 });165 </script>166 </head>167 <body>168 <a href='http://github.com/visionmedia/express'> 169 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' />
11 unmodified lines
181 <li><a href="contrib.html">Contributing</a></li>182 <li><a href="migrate.html">1.x Migration</a></li>183 </ul>184<div class='mp'>185<h2 id="Express">Express</h2>186<p class="man-name">187 <code>index</code>188</p>189<pre><code>var app = express.createServer();190191app.get('/', function(req, res){192 res.send('Hello World');
67 unmodified lines
modified:docs/migrate.1+5 added-2 removed
1.\" generated with Ronn/v0.6.62.\" http://github.com/rtomayko/ronn/1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "MIGRATE" "" "August 2010" "" ""5.6.SH "NAME"7\fBmigrate\fR8.9.SS "Built On Connect"10Express 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\.11.12.SS "Creating Applications"
335 unmodified lines
modified:docs/migrate.html+21 added
1<html>2 <head>3 <title>Express - node web framework</title>4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>5 <style>6 #tagline {7 margin-left: 75px;8 margin-bottom: 30px;
58 unmodified lines
67 ul li {68 margin: 0;69 padding: 2px 0;70 list-style: square; }71 ul li ul {72 margin: 0;73 padding-left: 12px;74 }7576 .sect {77 margin-left: 40px; }78
71 unmodified lines
150 background: rgba(0,0,0,0.1);151 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);152 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }153 </style>154 <script>155 $(function(){156 $('.section').hide();157 $('.toggle, a.section-title').toggle(function(){158 $(this).siblings('ul').fadeIn(300);159 return false;160 }, function(){161 $(this).siblings('ul').fadeOut(300);162 return false;163 });164 });165 </script>166 </head>167 <body>168 <a href='http://github.com/visionmedia/express'> 169 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' />
11 unmodified lines
181 <li><a href="contrib.html">Contributing</a></li>182 <li><a href="migrate.html">1.x Migration</a></li>183 </ul>184<div class='mp'>185<h2 id="Express">Express</h2>186<p class="man-name">187 <code>migrate</code>188</p>189<h3 id="Built-On-Connect">Built On Connect</h3>190191<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware192framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware
211 unmodified lines
modified:support/toc.js+3 added
15 unmodified lines
16 if (~title.indexOf('.')) {17 var parts = title.split('.'),18 recv = parts.shift(),19 method = parts.shift();20 if (recv == 'app') recv = 'Server';21 if (recv == 'req') recv = 'Request';22 if (recv == 'res') recv = 'Response';23 sections[recv] = sections[recv] || [];24 sections[recv].push('<li><a href="#' + id + '">' + method + '</a></li>');25 } else {26 toc.push('<li><a href="#' + id + '">' + title + '</a></li>');
20 unmodified lines